]> sigrok.org Git - libsigrok.git/blame - src/libsigrok-internal.h
serial: introduce local receive data buffer
[libsigrok.git] / src / libsigrok-internal.h
CommitLineData
1483577e 1/*
50985c20 2 * This file is part of the libsigrok project.
1483577e 3 *
13d8e03c 4 * Copyright (C) 2013 Bert Vermeulen <bert@biot.com>
1483577e
UH
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
d9251a2c
UH
20/**
21 * @file
22 *
23 * @internal
24 */
04cb9157 25
a5827886
UH
26#ifndef LIBSIGROK_LIBSIGROK_INTERNAL_H
27#define LIBSIGROK_LIBSIGROK_INTERNAL_H
1483577e 28
1df81f4b
GS
29#include "config.h"
30
cc8a7d25 31#include <glib.h>
c4f2dfd0 32#ifdef HAVE_LIBSERIALPORT
dc991353 33#include <libserialport.h>
c4f2dfd0 34#endif
fdcdfe53
GS
35#ifdef HAVE_LIBUSB_1_0
36#include <libusb.h>
37#endif
38#include <stdarg.h>
ad5aa993 39#include <stdint.h>
fdcdfe53 40#include <stdio.h>
ae4c1fb6 41#include <stdlib.h>
b08024a8 42
98654c99
DE
43struct zip;
44struct zip_stat;
45
393fb9cb
UH
46/**
47 * @file
48 *
49 * libsigrok private header file, only to be used internally.
50 */
51
4cea9eb2
UH
52/*--- Macros ----------------------------------------------------------------*/
53
54#ifndef ARRAY_SIZE
55#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
56#endif
57
58#ifndef ARRAY_AND_SIZE
59#define ARRAY_AND_SIZE(a) (a), ARRAY_SIZE(a)
60#endif
61
a4f9c35b 62/**
5bf0dd6a 63 * Read a 8 bits unsigned integer out of memory.
a4f9c35b 64 * @param x a pointer to the input memory
5bf0dd6a 65 * @return the corresponding unsigned integer
a4f9c35b
AJ
66 */
67#define R8(x) ((unsigned)((const uint8_t*)(x))[0])
68
e28ef28a 69/**
5bf0dd6a 70 * Read a 16 bits big endian unsigned integer out of memory.
e28ef28a 71 * @param x a pointer to the input memory
5bf0dd6a 72 * @return the corresponding unsigned integer
e28ef28a 73 */
d01c4c56 74#define RB16(x) (((unsigned)((const uint8_t*)(x))[0] << 8) | \
79a1176b 75 (unsigned)((const uint8_t*)(x))[1])
e28ef28a
AJ
76
77/**
5bf0dd6a 78 * Read a 16 bits little endian unsigned integer out of memory.
e28ef28a 79 * @param x a pointer to the input memory
5bf0dd6a 80 * @return the corresponding unsigned integer
e28ef28a 81 */
79a1176b
AJ
82#define RL16(x) (((unsigned)((const uint8_t*)(x))[1] << 8) | \
83 (unsigned)((const uint8_t*)(x))[0])
e28ef28a 84
4d376e08
SB
85/**
86 * Read a 16 bits big endian signed integer out of memory.
87 * @param x a pointer to the input memory
88 * @return the corresponding signed integer
89 */
90#define RB16S(x) ((int16_t) \
91 (((unsigned)((const uint8_t*)(x))[0] << 8) | \
92 (unsigned)((const uint8_t*)(x))[1]))
93
e28ef28a 94/**
5bf0dd6a 95 * Read a 16 bits little endian signed integer out of memory.
e28ef28a 96 * @param x a pointer to the input memory
5bf0dd6a
BV
97 * @return the corresponding signed integer
98 */
99#define RL16S(x) ((int16_t) \
af945a66 100 (((unsigned)((const uint8_t*)(x))[1] << 8) | \
5bf0dd6a
BV
101 (unsigned)((const uint8_t*)(x))[0]))
102
103/**
104 * Read a 32 bits big endian unsigned integer out of memory.
105 * @param x a pointer to the input memory
106 * @return the corresponding unsigned integer
e28ef28a 107 */
79a1176b 108#define RB32(x) (((unsigned)((const uint8_t*)(x))[0] << 24) | \
d01c4c56
SA
109 ((unsigned)((const uint8_t*)(x))[1] << 16) | \
110 ((unsigned)((const uint8_t*)(x))[2] << 8) | \
79a1176b 111 (unsigned)((const uint8_t*)(x))[3])
e28ef28a
AJ
112
113/**
5bf0dd6a 114 * Read a 32 bits little endian unsigned integer out of memory.
e28ef28a 115 * @param x a pointer to the input memory
5bf0dd6a 116 * @return the corresponding unsigned integer
e28ef28a 117 */
79a1176b 118#define RL32(x) (((unsigned)((const uint8_t*)(x))[3] << 24) | \
d01c4c56
SA
119 ((unsigned)((const uint8_t*)(x))[2] << 16) | \
120 ((unsigned)((const uint8_t*)(x))[1] << 8) | \
79a1176b 121 (unsigned)((const uint8_t*)(x))[0])
e28ef28a 122
4d376e08
SB
123/**
124 * Read a 32 bits big endian signed integer out of memory.
125 * @param x a pointer to the input memory
126 * @return the corresponding signed integer
127 */
128#define RB32S(x) ((int32_t) \
129 (((unsigned)((const uint8_t*)(x))[0] << 24) | \
130 ((unsigned)((const uint8_t*)(x))[1] << 16) | \
131 ((unsigned)((const uint8_t*)(x))[2] << 8) | \
132 (unsigned)((const uint8_t*)(x))[3]))
133
ea2d6d99 134/**
5bf0dd6a
BV
135 * Read a 32 bits little endian signed integer out of memory.
136 * @param x a pointer to the input memory
137 * @return the corresponding signed integer
138 */
139#define RL32S(x) ((int32_t) \
140 (((unsigned)((const uint8_t*)(x))[3] << 24) | \
d01c4c56
SA
141 ((unsigned)((const uint8_t*)(x))[2] << 16) | \
142 ((unsigned)((const uint8_t*)(x))[1] << 8) | \
5bf0dd6a
BV
143 (unsigned)((const uint8_t*)(x))[0]))
144
17b93fd7
TS
145/**
146 * Read a 64 bits big endian unsigned integer out of memory.
147 * @param x a pointer to the input memory
148 * @return the corresponding unsigned integer
149 */
150#define RB64(x) (((uint64_t)((const uint8_t*)(x))[0] << 56) | \
d01c4c56
SA
151 ((uint64_t)((const uint8_t*)(x))[1] << 48) | \
152 ((uint64_t)((const uint8_t*)(x))[2] << 40) | \
153 ((uint64_t)((const uint8_t*)(x))[3] << 32) | \
154 ((uint64_t)((const uint8_t*)(x))[4] << 24) | \
155 ((uint64_t)((const uint8_t*)(x))[5] << 16) | \
156 ((uint64_t)((const uint8_t*)(x))[6] << 8) | \
17b93fd7
TS
157 (uint64_t)((const uint8_t*)(x))[7])
158
8a66b077
SA
159/**
160 * Read a 64 bits little endian unsigned integer out of memory.
161 * @param x a pointer to the input memory
162 * @return the corresponding unsigned integer
163 */
164#define RL64(x) (((uint64_t)((const uint8_t*)(x))[7] << 56) | \
165 ((uint64_t)((const uint8_t*)(x))[6] << 48) | \
166 ((uint64_t)((const uint8_t*)(x))[5] << 40) | \
167 ((uint64_t)((const uint8_t*)(x))[4] << 32) | \
168 ((uint64_t)((const uint8_t*)(x))[3] << 24) | \
169 ((uint64_t)((const uint8_t*)(x))[2] << 16) | \
170 ((uint64_t)((const uint8_t*)(x))[1] << 8) | \
171 (uint64_t)((const uint8_t*)(x))[0])
172
173/**
174 * Read a 64 bits little endian signed integer out of memory.
175 * @param x a pointer to the input memory
176 * @return the corresponding unsigned integer
177 */
178#define RL64S(x) ((int64_t) \
179 (((uint64_t)((const uint8_t*)(x))[7] << 56) | \
180 ((uint64_t)((const uint8_t*)(x))[6] << 48) | \
181 ((uint64_t)((const uint8_t*)(x))[5] << 40) | \
182 ((uint64_t)((const uint8_t*)(x))[4] << 32) | \
183 ((uint64_t)((const uint8_t*)(x))[3] << 24) | \
184 ((uint64_t)((const uint8_t*)(x))[2] << 16) | \
185 ((uint64_t)((const uint8_t*)(x))[1] << 8) | \
186 (uint64_t)((const uint8_t*)(x))[0]))
187
a2632bca
AJ
188/**
189 * Read a 32 bits big endian float out of memory.
190 * @param x a pointer to the input memory
191 * @return the corresponding float
192 */
193#define RBFL(x) ((union { uint32_t u; float f; }) { .u = RB32(x) }.f)
194
195/**
196 * Read a 32 bits little endian float out of memory.
197 * @param x a pointer to the input memory
198 * @return the corresponding float
199 */
200#define RLFL(x) ((union { uint32_t u; float f; }) { .u = RL32(x) }.f)
201
5bf0dd6a
BV
202/**
203 * Write a 8 bits unsigned integer to memory.
ea2d6d99 204 * @param p a pointer to the output memory
5bf0dd6a 205 * @param x the input unsigned integer
ea2d6d99 206 */
0c5f2abc 207#define W8(p, x) do { ((uint8_t*)(p))[0] = (uint8_t) (x); } while (0)
ea2d6d99
AJ
208
209/**
5bf0dd6a 210 * Write a 16 bits unsigned integer to memory stored as big endian.
ea2d6d99 211 * @param p a pointer to the output memory
5bf0dd6a 212 * @param x the input unsigned integer
ea2d6d99
AJ
213 */
214#define WB16(p, x) do { ((uint8_t*)(p))[1] = (uint8_t) (x); \
0c5f2abc 215 ((uint8_t*)(p))[0] = (uint8_t)((x)>>8); } while (0)
ea2d6d99
AJ
216
217/**
5bf0dd6a 218 * Write a 16 bits unsigned integer to memory stored as little endian.
ea2d6d99 219 * @param p a pointer to the output memory
5bf0dd6a 220 * @param x the input unsigned integer
ea2d6d99
AJ
221 */
222#define WL16(p, x) do { ((uint8_t*)(p))[0] = (uint8_t) (x); \
0c5f2abc 223 ((uint8_t*)(p))[1] = (uint8_t)((x)>>8); } while (0)
ea2d6d99
AJ
224
225/**
5bf0dd6a 226 * Write a 32 bits unsigned integer to memory stored as big endian.
ea2d6d99 227 * @param p a pointer to the output memory
5bf0dd6a 228 * @param x the input unsigned integer
ea2d6d99
AJ
229 */
230#define WB32(p, x) do { ((uint8_t*)(p))[3] = (uint8_t) (x); \
231 ((uint8_t*)(p))[2] = (uint8_t)((x)>>8); \
232 ((uint8_t*)(p))[1] = (uint8_t)((x)>>16); \
0c5f2abc 233 ((uint8_t*)(p))[0] = (uint8_t)((x)>>24); } while (0)
ea2d6d99
AJ
234
235/**
5bf0dd6a 236 * Write a 32 bits unsigned integer to memory stored as little endian.
ea2d6d99 237 * @param p a pointer to the output memory
5bf0dd6a 238 * @param x the input unsigned integer
ea2d6d99
AJ
239 */
240#define WL32(p, x) do { ((uint8_t*)(p))[0] = (uint8_t) (x); \
241 ((uint8_t*)(p))[1] = (uint8_t)((x)>>8); \
242 ((uint8_t*)(p))[2] = (uint8_t)((x)>>16); \
0c5f2abc 243 ((uint8_t*)(p))[3] = (uint8_t)((x)>>24); } while (0)
ea2d6d99 244
a2632bca
AJ
245/**
246 * Write a 32 bits float to memory stored as big endian.
247 * @param p a pointer to the output memory
248 * @param x the input float
249 */
250#define WBFL(p, x) WB32(p, (union { uint32_t u; float f; }) { .f = x }.u)
251
252/**
253 * Write a 32 bits float to memory stored as little endian.
254 * @param p a pointer to the output memory
255 * @param x the input float
256 */
257#define WLFL(p, x) WL32(p, (union { uint32_t u; float f; }) { .f = x }.u)
258
6bf4273e
UH
259/* Portability fixes for FreeBSD. */
260#ifdef __FreeBSD__
261#define LIBUSB_CLASS_APPLICATION 0xfe
15eea61a 262#define libusb_has_capability(x) 0
6bf4273e
UH
263#define libusb_handle_events_timeout_completed(ctx, tv, c) \
264 libusb_handle_events_timeout(ctx, tv)
265#endif
266
1685c276
BV
267/* Static definitions of structs ending with an all-zero entry are a
268 * problem when compiling with -Wmissing-field-initializers: GCC
269 * suppresses the warning only with { 0 }, clang wants { } */
270#ifdef __clang__
271#define ALL_ZERO { }
272#else
273#define ALL_ZERO { 0 }
274#endif
275
dd5c48a6
LPC
276#ifdef __APPLE__
277#define SR_DRIVER_LIST_SECTION "__DATA,__sr_driver_list"
278#else
279#define SR_DRIVER_LIST_SECTION "sr_driver_list"
280#endif
281
282/**
283 * Register a list of hardware drivers.
284 *
285 * This macro can be used to register multiple hardware drivers to the library.
286 * This is useful when a driver supports multiple similar but slightly
287 * different devices that require different sr_dev_driver struct definitions.
288 *
289 * For registering only a single driver see SR_REGISTER_DEV_DRIVER().
290 *
291 * Example:
292 * @code{c}
293 * #define MY_DRIVER(_name) \
294 * &(struct sr_dev_driver){ \
295 * .name = _name, \
296 * ...
297 * };
298 *
299 * SR_REGISTER_DEV_DRIVER_LIST(my_driver_infos,
300 * MY_DRIVER("driver 1"),
301 * MY_DRIVER("driver 2"),
302 * ...
303 * );
304 * @endcode
305 *
306 * @param name Name to use for the driver list identifier.
307 * @param ... Comma separated list of pointers to sr_dev_driver structs.
308 */
309#define SR_REGISTER_DEV_DRIVER_LIST(name, ...) \
310 static const struct sr_dev_driver *name[] \
311 __attribute__((section (SR_DRIVER_LIST_SECTION), used, \
312 aligned(sizeof(struct sr_dev_driver *)))) \
313 = { \
314 __VA_ARGS__ \
315 };
316
317/**
318 * Register a hardware driver.
319 *
320 * This macro is used to register a hardware driver with the library. It has
321 * to be used in order to make the driver accessible to applications using the
322 * library.
323 *
324 * The macro invocation should be placed directly under the struct
325 * sr_dev_driver definition.
326 *
327 * Example:
328 * @code{c}
329 * static struct sr_dev_driver driver_info = {
330 * .name = "driver",
331 * ....
332 * };
333 * SR_REGISTER_DEV_DRIVER(driver_info);
334 * @endcode
335 *
336 * @param name Identifier name of sr_dev_driver struct to register.
337 */
338#define SR_REGISTER_DEV_DRIVER(name) \
339 SR_REGISTER_DEV_DRIVER_LIST(name##_list, &name);
340
ced48274 341SR_API void sr_drivers_init(struct sr_context *context);
5d8b3913 342
b8072700 343struct sr_context {
032da34b 344 struct sr_dev_driver **driver_list;
785b9ff2
PS
345#ifdef HAVE_LIBUSB_1_0
346 libusb_context *libusb_ctx;
347#endif
bee24666
DE
348 sr_resource_open_callback resource_open_cb;
349 sr_resource_close_callback resource_close_cb;
350 sr_resource_read_callback resource_read_cb;
351 void *resource_cb_data;
b8072700
PS
352};
353
20e88821
BV
354/** Input module metadata keys. */
355enum sr_input_meta_keys {
356 /** The input filename, if there is one. */
357 SR_INPUT_META_FILENAME = 0x01,
358 /** The input file's size in bytes. */
359 SR_INPUT_META_FILESIZE = 0x02,
360 /** The first 128 bytes of the file, provided as a GString. */
361 SR_INPUT_META_HEADER = 0x04,
20e88821
BV
362
363 /** The module cannot identify a file without this metadata. */
364 SR_INPUT_META_REQUIRED = 0x80,
365};
366
d514d35d
BV
367/** Input (file) module struct. */
368struct sr_input {
369 /**
370 * A pointer to this input module's 'struct sr_input_module'.
d514d35d 371 */
17bfaca6
BV
372 const struct sr_input_module *module;
373 GString *buf;
d514d35d 374 struct sr_dev_inst *sdi;
d0181813 375 gboolean sdi_ready;
17bfaca6 376 void *priv;
d514d35d
BV
377};
378
379/** Input (file) module driver. */
380struct sr_input_module {
17bfaca6 381 /**
d65fcbcd 382 * A unique ID for this input module, suitable for use in command-line
17bfaca6
BV
383 * clients, [a-z0-9-]. Must not be NULL.
384 */
385 const char *id;
d514d35d
BV
386
387 /**
d65fcbcd 388 * A unique name for this input module, suitable for use in GUI
17bfaca6 389 * clients, can contain UTF-8. Must not be NULL.
d514d35d 390 */
17bfaca6 391 const char *name;
d514d35d
BV
392
393 /**
d65fcbcd 394 * A short description of the input module. Must not be NULL.
d514d35d 395 *
d65fcbcd 396 * This can be displayed by frontends, e.g. when selecting the input
17bfaca6
BV
397 * module for saving a file.
398 */
399 const char *desc;
400
c7bc82ff
JH
401 /**
402 * A NULL terminated array of strings containing a list of file name
403 * extensions typical for the input file format, or NULL if there is
404 * no typical extension for this file format.
405 */
406 const char *const *exts;
407
17bfaca6
BV
408 /**
409 * Zero-terminated list of metadata items the module needs to be able
410 * to identify an input stream. Can be all-zero, if the module cannot
411 * identify streams at all, i.e. has to be forced into use.
412 *
413 * Each item is one of:
414 * SR_INPUT_META_FILENAME
415 * SR_INPUT_META_FILESIZE
416 * SR_INPUT_META_HEADER
17bfaca6
BV
417 *
418 * If the high bit (SR_INPUT META_REQUIRED) is set, the module cannot
419 * identify a stream without the given metadata.
420 */
421 const uint8_t metadata[8];
422
423 /**
424 * Returns a NULL-terminated list of options this module can take.
425 * Can be NULL, if the module has no options.
426 */
2c240774 427 const struct sr_option *(*options) (void);
17bfaca6
BV
428
429 /**
430 * Check if this input module can load and parse the specified stream.
431 *
432 * @param[in] metadata Metadata the module can use to identify the stream.
54ee427d
GS
433 * @param[out] confidence "Strength" of the detection.
434 * Specialized handlers can take precedence over generic/basic support.
d514d35d 435 *
4f979115 436 * @retval SR_OK This module knows the format.
753793ef 437 * @retval SR_ERR_NA There wasn't enough data for this module to
4f979115 438 * positively identify the format.
d9251a2c
UH
439 * @retval SR_ERR_DATA This module knows the format, but cannot handle
440 * it. This means the stream is either corrupt, or indicates a
441 * feature that the module does not support.
4f979115 442 * @retval SR_ERR This module does not know the format.
54ee427d
GS
443 *
444 * Lower numeric values of 'confidence' mean that the input module
445 * stronger believes in its capability to handle this specific format.
446 * This way, multiple input modules can claim support for a format,
447 * and the application can pick the best match, or try fallbacks
448 * in case of errors. This approach also copes with formats that
449 * are unreliable to detect in the absence of magic signatures.
d514d35d 450 */
54ee427d 451 int (*format_match) (GHashTable *metadata, unsigned int *confidence);
d514d35d
BV
452
453 /**
454 * Initialize the input module.
455 *
d514d35d
BV
456 * @retval SR_OK Success
457 * @retval other Negative error code.
458 */
17bfaca6 459 int (*init) (struct sr_input *in, GHashTable *options);
d514d35d
BV
460
461 /**
753793ef 462 * Send data to the specified input instance.
d514d35d 463 *
753793ef
BV
464 * When an input module instance is created with sr_input_new(), this
465 * function is used to feed data to the instance.
d514d35d 466 *
753793ef
BV
467 * As enough data gets fed into this function to completely populate
468 * the device instance associated with this input instance, this is
469 * guaranteed to return the moment it's ready. This gives the caller
470 * the chance to examine the device instance, attach session callbacks
471 * and so on.
17bfaca6
BV
472 *
473 * @retval SR_OK Success
474 * @retval other Negative error code.
475 */
d0181813 476 int (*receive) (struct sr_input *in, GString *buf);
17bfaca6 477
753793ef
BV
478 /**
479 * Signal the input module no more data will come.
480 *
481 * This will cause the module to process any data it may have buffered.
482 * The SR_DF_END packet will also typically be sent at this time.
483 */
7066fd46
BV
484 int (*end) (struct sr_input *in);
485
d9251a2c
UH
486 /**
487 * Reset the input module's input handling structures.
488 *
489 * Causes the input module to reset its internal state so that we can
490 * re-send the input data from the beginning without having to
491 * re-create the entire input module.
492 *
493 * @retval SR_OK Success.
494 * @retval other Negative error code.
495 */
b6b4f03e
SA
496 int (*reset) (struct sr_input *in);
497
17bfaca6
BV
498 /**
499 * This function is called after the caller is finished using
500 * the input module, and can be used to free any internal
501 * resources the module may keep.
d514d35d 502 *
753793ef
BV
503 * This function is optional.
504 *
d514d35d
BV
505 * @retval SR_OK Success
506 * @retval other Negative error code.
507 */
d5cc282f 508 void (*cleanup) (struct sr_input *in);
d514d35d
BV
509};
510
a755b0e1
BV
511/** Output module instance. */
512struct sr_output {
d9251a2c 513 /** A pointer to this output's module. */
a755b0e1
BV
514 const struct sr_output_module *module;
515
516 /**
517 * The device for which this output module is creating output. This
518 * can be used by the module to find out channel names and numbers.
519 */
520 const struct sr_dev_inst *sdi;
521
81b3ce37
SA
522 /**
523 * The name of the file that the data should be written to.
524 */
525 const char *filename;
526
a755b0e1
BV
527 /**
528 * A generic pointer which can be used by the module to keep internal
529 * state between calls into its callback functions.
530 *
531 * For example, the module might store a pointer to a chunk of output
532 * there, and only flush it when it reaches a certain size.
533 */
d686c5ec 534 void *priv;
a755b0e1
BV
535};
536
537/** Output module driver. */
538struct sr_output_module {
539 /**
540 * A unique ID for this output module, suitable for use in command-line
541 * clients, [a-z0-9-]. Must not be NULL.
542 */
2c240774 543 const char *id;
a755b0e1
BV
544
545 /**
546 * A unique name for this output module, suitable for use in GUI
547 * clients, can contain UTF-8. Must not be NULL.
548 */
549 const char *name;
550
551 /**
552 * A short description of the output module. Must not be NULL.
553 *
554 * This can be displayed by frontends, e.g. when selecting the output
555 * module for saving a file.
556 */
2c240774 557 const char *desc;
a755b0e1 558
8a174d23
JH
559 /**
560 * A NULL terminated array of strings containing a list of file name
561 * extensions typical for the input file format, or NULL if there is
562 * no typical extension for this file format.
563 */
564 const char *const *exts;
565
3cd4b381
SA
566 /**
567 * Bitfield containing flags that describe certain properties
568 * this output module may or may not have.
569 * @see sr_output_flags
570 */
571 const uint64_t flags;
572
a755b0e1
BV
573 /**
574 * Returns a NULL-terminated list of options this module can take.
575 * Can be NULL, if the module has no options.
a755b0e1 576 */
af7d656d 577 const struct sr_option *(*options) (void);
a755b0e1
BV
578
579 /**
580 * This function is called once, at the beginning of an output stream.
581 *
582 * The device struct will be available in the output struct passed in,
583 * as well as the param field -- which may be NULL or an empty string,
584 * if no parameter was passed.
585 *
586 * The module can use this to initialize itself, create a struct for
587 * keeping state and storing it in the <code>internal</code> field.
588 *
589 * @param o Pointer to the respective 'struct sr_output'.
590 *
591 * @retval SR_OK Success
592 * @retval other Negative error code.
593 */
594 int (*init) (struct sr_output *o, GHashTable *options);
595
596 /**
f3f19d11 597 * This function is passed a copy of every packet in the data feed.
a755b0e1
BV
598 * Any output generated by the output module in response to the
599 * packet should be returned in a newly allocated GString
600 * <code>out</code>, which will be freed by the caller.
601 *
602 * Packets not of interest to the output module can just be ignored,
603 * and the <code>out</code> parameter set to NULL.
604 *
605 * @param o Pointer to the respective 'struct sr_output'.
606 * @param sdi The device instance that generated the packet.
607 * @param packet The complete packet.
608 * @param out A pointer where a GString * should be stored if
609 * the module generates output, or NULL if not.
610 *
611 * @retval SR_OK Success
612 * @retval other Negative error code.
613 */
614 int (*receive) (const struct sr_output *o,
615 const struct sr_datafeed_packet *packet, GString **out);
616
617 /**
618 * This function is called after the caller is finished using
619 * the output module, and can be used to free any internal
620 * resources the module may keep.
621 *
622 * @retval SR_OK Success
623 * @retval other Negative error code.
624 */
625 int (*cleanup) (struct sr_output *o);
626};
627
790320f6
UH
628/** Transform module instance. */
629struct sr_transform {
d9251a2c 630 /** A pointer to this transform's module. */
790320f6
UH
631 const struct sr_transform_module *module;
632
633 /**
634 * The device for which this transform module is used. This
635 * can be used by the module to find out channel names and numbers.
636 */
637 const struct sr_dev_inst *sdi;
638
639 /**
640 * A generic pointer which can be used by the module to keep internal
641 * state between calls into its callback functions.
642 */
643 void *priv;
644};
645
646struct sr_transform_module {
647 /**
648 * A unique ID for this transform module, suitable for use in
649 * command-line clients, [a-z0-9-]. Must not be NULL.
650 */
2c240774 651 const char *id;
790320f6
UH
652
653 /**
654 * A unique name for this transform module, suitable for use in GUI
655 * clients, can contain UTF-8. Must not be NULL.
656 */
657 const char *name;
658
659 /**
660 * A short description of the transform module. Must not be NULL.
661 *
662 * This can be displayed by frontends, e.g. when selecting
663 * which transform module(s) to add.
664 */
2c240774 665 const char *desc;
790320f6
UH
666
667 /**
668 * Returns a NULL-terminated list of options this transform module
669 * can take. Can be NULL, if the transform module has no options.
670 */
671 const struct sr_option *(*options) (void);
672
673 /**
674 * This function is called once, at the beginning of a stream.
675 *
676 * @param t Pointer to the respective 'struct sr_transform'.
677 * @param options Hash table of options for this transform module.
678 * Can be NULL if no options are to be used.
679 *
680 * @retval SR_OK Success
681 * @retval other Negative error code.
682 */
683 int (*init) (struct sr_transform *t, GHashTable *options);
684
685 /**
686 * This function is passed a pointer to every packet in the data feed.
687 *
688 * It can either return (in packet_out) a pointer to another packet
689 * (possibly the exact same packet it got as input), or NULL.
690 *
691 * @param t Pointer to the respective 'struct sr_transform'.
692 * @param packet_in Pointer to a datafeed packet.
693 * @param packet_out Pointer to the resulting datafeed packet after
694 * this function was run. If NULL, the transform
695 * module intentionally didn't output a new packet.
696 *
697 * @retval SR_OK Success
698 * @retval other Negative error code.
699 */
700 int (*receive) (const struct sr_transform *t,
701 struct sr_datafeed_packet *packet_in,
702 struct sr_datafeed_packet **packet_out);
703
704 /**
705 * This function is called after the caller is finished using
706 * the transform module, and can be used to free any internal
707 * resources the module may keep.
708 *
709 * @retval SR_OK Success
710 * @retval other Negative error code.
711 */
712 int (*cleanup) (struct sr_transform *t);
713};
714
69890f73 715#ifdef HAVE_LIBUSB_1_0
04cb9157 716/** USB device instance */
d68e2d1a 717struct sr_usb_dev_inst {
98582bf5
BV
718 /** USB bus */
719 uint8_t bus;
720 /** Device address on USB bus */
721 uint8_t address;
722 /** libusb device handle */
723 struct libusb_device_handle *devhdl;
69890f73
UH
724};
725#endif
726
1ac8c218 727struct sr_serial_dev_inst;
1df81f4b 728#ifdef HAVE_SERIAL_COMM
a7b8692e 729struct ser_lib_functions;
d68e2d1a 730struct sr_serial_dev_inst {
98582bf5
BV
731 /** Port name, e.g. '/dev/tty42'. */
732 char *port;
733 /** Comm params for serial_set_paramstr(). */
734 char *serialcomm;
a7b8692e 735 struct ser_lib_functions *lib_funcs;
639c6f61
GS
736 struct {
737 int bit_rate;
738 int data_bits;
739 int parity_bits;
740 int stop_bits;
741 } comm_params;
ad5aa993 742 GString *rcv_buffer;
a7b8692e 743#ifdef HAVE_LIBSERIALPORT
98582bf5 744 /** libserialport port handle */
271392d9 745 struct sp_port *sp_data;
a7b8692e 746#endif
69890f73 747};
c4f2dfd0 748#endif
69890f73 749
ae67644f
ML
750struct sr_usbtmc_dev_inst {
751 char *device;
752 int fd;
753};
754
026c822d
UH
755/* Private driver context. */
756struct drv_context {
98582bf5
BV
757 /** sigrok context */
758 struct sr_context *sr_ctx;
026c822d
UH
759 GSList *instances;
760};
761
48a486cd
BV
762/*--- log.c -----------------------------------------------------------------*/
763
00f0016c 764#if defined(_WIN32) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4))
7419638d
DE
765/*
766 * On MinGW, we need to specify the gnu_printf format flavor or GCC
767 * will assume non-standard Microsoft printf syntax.
768 */
769SR_PRIV int sr_log(int loglevel, const char *format, ...)
770 __attribute__((__format__ (__gnu_printf__, 2, 3)));
771#else
be92d5b4 772SR_PRIV int sr_log(int loglevel, const char *format, ...) G_GNUC_PRINTF(2, 3);
7419638d 773#endif
48a486cd 774
3544f848 775/* Message logging helpers with subsystem-specific prefix string. */
be92d5b4
DE
776#define sr_spew(...) sr_log(SR_LOG_SPEW, LOG_PREFIX ": " __VA_ARGS__)
777#define sr_dbg(...) sr_log(SR_LOG_DBG, LOG_PREFIX ": " __VA_ARGS__)
778#define sr_info(...) sr_log(SR_LOG_INFO, LOG_PREFIX ": " __VA_ARGS__)
779#define sr_warn(...) sr_log(SR_LOG_WARN, LOG_PREFIX ": " __VA_ARGS__)
780#define sr_err(...) sr_log(SR_LOG_ERR, LOG_PREFIX ": " __VA_ARGS__)
3544f848 781
48a486cd
BV
782/*--- device.c --------------------------------------------------------------*/
783
cffdc3e6
ML
784/** Scan options supported by a driver. */
785#define SR_CONF_SCAN_OPTIONS 0x7FFF0000
786
787/** Device options for a particular device. */
788#define SR_CONF_DEVICE_OPTIONS 0x7FFF0001
789
e318f01b
ML
790/** Mask for separating config keys from capabilities. */
791#define SR_CONF_MASK 0x1fffffff
792
f3ca73ed 793/** Values for the changes argument of sr_dev_driver.config_channel_set. */
2a854d71 794enum {
fca75cbb 795 /** The enabled state of the channel has been changed. */
3f239f08 796 SR_CHANNEL_SET_ENABLED = 1 << 0,
2a854d71
DE
797};
798
5e23fcab
ML
799SR_PRIV struct sr_channel *sr_channel_new(struct sr_dev_inst *sdi,
800 int index, int type, gboolean enabled, const char *name);
fe71c7e4
GS
801SR_PRIV void sr_channel_free(struct sr_channel *ch);
802SR_PRIV void sr_channel_free_cb(void *p);
9c24d16a
BV
803SR_PRIV struct sr_channel *sr_next_enabled_channel(const struct sr_dev_inst *sdi,
804 struct sr_channel *cur_channel);
712f981d
GS
805SR_PRIV gboolean sr_channels_differ(struct sr_channel *ch1, struct sr_channel *ch2);
806SR_PRIV gboolean sr_channel_lists_differ(GSList *l1, GSList *l2);
48a486cd 807
96727ef0
UH
808/** Device instance data */
809struct sr_dev_inst {
810 /** Device driver. */
811 struct sr_dev_driver *driver;
812 /** Device instance status. SR_ST_NOT_FOUND, etc. */
813 int status;
814 /** Device instance type. SR_INST_USB, etc. */
815 int inst_type;
816 /** Device vendor. */
817 char *vendor;
818 /** Device model. */
819 char *model;
820 /** Device version. */
821 char *version;
822 /** Serial number. */
823 char *serial_num;
824 /** Connection string to uniquely identify devices. */
825 char *connection_id;
826 /** List of channels. */
827 GSList *channels;
828 /** List of sr_channel_group structs */
829 GSList *channel_groups;
830 /** Device instance connection data (used?) */
831 void *conn;
832 /** Device instance private data (used?) */
833 void *priv;
834 /** Session to which this device is currently assigned. */
835 struct sr_session *session;
836};
837
48a486cd 838/* Generic device instances */
48a486cd 839SR_PRIV void sr_dev_inst_free(struct sr_dev_inst *sdi);
48a486cd 840
545f9786 841#ifdef HAVE_LIBUSB_1_0
69890f73 842/* USB-specific instances */
d68e2d1a 843SR_PRIV struct sr_usb_dev_inst *sr_usb_dev_inst_new(uint8_t bus,
69890f73 844 uint8_t address, struct libusb_device_handle *hdl);
d68e2d1a 845SR_PRIV void sr_usb_dev_inst_free(struct sr_usb_dev_inst *usb);
69890f73
UH
846#endif
847
1df81f4b 848#ifdef HAVE_SERIAL_COMM
1ac8c218
GS
849#ifndef HAVE_LIBSERIALPORT
850/*
851 * Some identifiers which initially got provided by libserialport are
852 * used internally within the libsigrok serial layer's implementation,
853 * while libserialport no longer is the exclusive provider of serial
854 * communication support. Declare the identifiers here so they remain
855 * available across all build configurations.
856 */
857enum libsp_parity {
858 SP_PARITY_NONE = 0,
859 SP_PARITY_ODD = 1,
860 SP_PARITY_EVEN = 2,
861 SP_PARITY_MARK = 3,
862 SP_PARITY_SPACE = 4,
863};
864
865enum libsp_flowcontrol {
866 SP_FLOWCONTROL_NONE = 0,
867 SP_FLOWCONTROL_XONXOFF = 1,
868 SP_FLOWCONTROL_RTSCTS = 2,
869 SP_FLOWCONTROL_DTRDSR = 3,
870};
871#endif
872
69890f73 873/* Serial-specific instances */
299bdb24
BV
874SR_PRIV struct sr_serial_dev_inst *sr_serial_dev_inst_new(const char *port,
875 const char *serialcomm);
d68e2d1a 876SR_PRIV void sr_serial_dev_inst_free(struct sr_serial_dev_inst *serial);
c4f2dfd0 877#endif
69890f73 878
ae67644f
ML
879/* USBTMC-specific instances */
880SR_PRIV struct sr_usbtmc_dev_inst *sr_usbtmc_dev_inst_new(const char *device);
881SR_PRIV void sr_usbtmc_dev_inst_free(struct sr_usbtmc_dev_inst *usbtmc);
b08024a8 882
c09f0b57 883/*--- hwdriver.c ------------------------------------------------------------*/
996b0c72 884
13fef1ed 885SR_PRIV const GVariantType *sr_variant_type_get(int datatype);
584560f1 886SR_PRIV int sr_variant_type_check(uint32_t key, GVariant *data);
032da34b 887SR_PRIV void sr_hw_cleanup_all(const struct sr_context *ctx);
584560f1 888SR_PRIV struct sr_config *sr_config_new(uint32_t key, GVariant *data);
722db131 889SR_PRIV void sr_config_free(struct sr_config *src);
f670835f 890SR_PRIV int sr_dev_acquisition_start(struct sr_dev_inst *sdi);
d2f7c417 891SR_PRIV int sr_dev_acquisition_stop(struct sr_dev_inst *sdi);
996b0c72 892
a1645fcd
BV
893/*--- session.c -------------------------------------------------------------*/
894
e2b23821 895struct sr_session {
4ed5d21d
ML
896 /** Context this session exists in. */
897 struct sr_context *ctx;
c0e3ba4b 898 /** List of struct sr_dev_inst pointers. */
e2b23821 899 GSList *devs;
1de3cced
ML
900 /** List of struct sr_dev_inst pointers owned by this session. */
901 GSList *owned_devs;
e2b23821
UH
902 /** List of struct datafeed_callback pointers. */
903 GSList *datafeed_callbacks;
c0a1e532 904 GSList *transforms;
7b5e6d29 905 struct sr_trigger *trigger;
62d7945f 906
5de0fc55
DE
907 /** Callback to invoke on session stop. */
908 sr_session_stopped_callback stopped_callback;
909 /** User data to be passed to the session stop callback. */
910 void *stopped_cb_data;
911
2e5e3df4 912 /** Mutex protecting the main context pointer. */
c2bf5506
DE
913 GMutex main_mutex;
914 /** Context of the session main loop. */
915 GMainContext *main_context;
e2b23821 916
c2bf5506
DE
917 /** Registered event sources for this session. */
918 GHashTable *event_sources;
919 /** Session main loop. */
920 GMainLoop *main_loop;
5de0fc55
DE
921 /** ID of idle source for dispatching the session stop notification. */
922 unsigned int stop_check_id;
2e5e3df4
DE
923 /** Whether the session has been started. */
924 gboolean running;
e2b23821
UH
925};
926
62d7945f 927SR_PRIV int sr_session_source_add_internal(struct sr_session *session,
c2bf5506 928 void *key, GSource *source);
92248e78 929SR_PRIV int sr_session_source_remove_internal(struct sr_session *session,
c2bf5506
DE
930 void *key);
931SR_PRIV int sr_session_source_destroyed(struct sr_session *session,
932 void *key, GSource *source);
cbc1413f
DE
933SR_PRIV int sr_session_fd_source_add(struct sr_session *session,
934 void *key, gintptr fd, int events, int timeout,
935 sr_receive_data_callback cb, void *cb_data);
ee9953ef
DE
936
937SR_PRIV int sr_session_source_add(struct sr_session *session, int fd,
938 int events, int timeout, sr_receive_data_callback cb, void *cb_data);
939SR_PRIV int sr_session_source_add_pollfd(struct sr_session *session,
940 GPollFD *pollfd, int timeout, sr_receive_data_callback cb,
941 void *cb_data);
942SR_PRIV int sr_session_source_add_channel(struct sr_session *session,
943 GIOChannel *channel, int events, int timeout,
944 sr_receive_data_callback cb, void *cb_data);
945SR_PRIV int sr_session_source_remove(struct sr_session *session, int fd);
946SR_PRIV int sr_session_source_remove_pollfd(struct sr_session *session,
947 GPollFD *pollfd);
948SR_PRIV int sr_session_source_remove_channel(struct sr_session *session,
949 GIOChannel *channel);
950
7d1a4a52
FS
951SR_PRIV int sr_session_send_meta(const struct sr_dev_inst *sdi,
952 uint32_t key, GVariant *var);
de4d3f99 953SR_PRIV int sr_session_send(const struct sr_dev_inst *sdi,
ae5859ff 954 const struct sr_datafeed_packet *packet);
f438e0c9 955SR_PRIV int sr_sessionfile_check(const char *filename);
7c69b528
SA
956SR_PRIV struct sr_dev_inst *sr_session_prepare_sdi(const char *filename,
957 struct sr_session **session);
a1645fcd 958
98654c99
DE
959/*--- session_file.c --------------------------------------------------------*/
960
a6dc3dac
DE
961#if !HAVE_ZIP_DISCARD
962/* Replace zip_discard() if not available. */
963#define zip_discard(zip) sr_zip_discard(zip)
964SR_PRIV void sr_zip_discard(struct zip *archive);
965#endif
966
98654c99
DE
967SR_PRIV GKeyFile *sr_sessionfile_read_metadata(struct zip *archive,
968 const struct zip_stat *entry);
969
41caa319
AJ
970/*--- analog.c --------------------------------------------------------------*/
971
edb691fc 972SR_PRIV int sr_analog_init(struct sr_datafeed_analog *analog,
41caa319
AJ
973 struct sr_analog_encoding *encoding,
974 struct sr_analog_meaning *meaning,
975 struct sr_analog_spec *spec,
976 int digits);
977
063e7aef
UH
978/*--- std.c -----------------------------------------------------------------*/
979
144f6660
UH
980typedef int (*dev_close_callback)(struct sr_dev_inst *sdi);
981typedef void (*std_dev_clear_callback)(void *priv);
cd2f0fe2 982
c45c32ce 983SR_PRIV int std_init(struct sr_dev_driver *di, struct sr_context *sr_ctx);
700d6b64 984SR_PRIV int std_cleanup(const struct sr_dev_driver *di);
4d67b9d9
UH
985SR_PRIV int std_dummy_dev_open(struct sr_dev_inst *sdi);
986SR_PRIV int std_dummy_dev_close(struct sr_dev_inst *sdi);
987SR_PRIV int std_dummy_dev_acquisition_start(const struct sr_dev_inst *sdi);
988SR_PRIV int std_dummy_dev_acquisition_stop(struct sr_dev_inst *sdi);
1df81f4b 989#ifdef HAVE_SERIAL_COMM
23dc6661 990SR_PRIV int std_serial_dev_open(struct sr_dev_inst *sdi);
1b38775b 991SR_PRIV int std_serial_dev_acquisition_stop(struct sr_dev_inst *sdi);
c4f2dfd0 992#endif
bee2b016
LPC
993SR_PRIV int std_session_send_df_header(const struct sr_dev_inst *sdi);
994SR_PRIV int std_session_send_df_end(const struct sr_dev_inst *sdi);
b7602846
SA
995SR_PRIV int std_session_send_frame_begin(const struct sr_dev_inst *sdi);
996SR_PRIV int std_session_send_frame_end(const struct sr_dev_inst *sdi);
6e43c3d5 997SR_PRIV int std_dev_clear_with_callback(const struct sr_dev_driver *driver,
144f6660 998 std_dev_clear_callback clear_private);
f778bf02 999SR_PRIV int std_dev_clear(const struct sr_dev_driver *driver);
c01bf34c 1000SR_PRIV GSList *std_dev_list(const struct sr_dev_driver *di);
043e899a 1001SR_PRIV int std_serial_dev_close(struct sr_dev_inst *sdi);
15a5bfe4 1002SR_PRIV GSList *std_scan_complete(struct sr_dev_driver *di, GSList *devices);
4afdfd46 1003
e66d1892
UH
1004SR_PRIV int std_opts_config_list(uint32_t key, GVariant **data,
1005 const struct sr_dev_inst *sdi, const struct sr_channel_group *cg,
1006 const uint32_t scanopts[], size_t scansize, const uint32_t drvopts[],
1007 size_t drvsize, const uint32_t devopts[], size_t devsize);
1008
23772462
UH
1009extern SR_PRIV const uint32_t NO_OPTS[1];
1010
e66d1892
UH
1011#define STD_CONFIG_LIST(key, data, sdi, cg, scanopts, drvopts, devopts) \
1012 std_opts_config_list(key, data, sdi, cg, ARRAY_AND_SIZE(scanopts), \
1013 ARRAY_AND_SIZE(drvopts), ARRAY_AND_SIZE(devopts))
1014
58ffcf97 1015SR_PRIV GVariant *std_gvar_tuple_array(const uint64_t a[][2], unsigned int n);
db944f16 1016SR_PRIV GVariant *std_gvar_tuple_rational(const struct sr_rational *r, unsigned int n);
463160cb
UH
1017SR_PRIV GVariant *std_gvar_samplerates(const uint64_t samplerates[], unsigned int n);
1018SR_PRIV GVariant *std_gvar_samplerates_steps(const uint64_t samplerates[], unsigned int n);
54d471f4
UH
1019SR_PRIV GVariant *std_gvar_min_max_step(double min, double max, double step);
1020SR_PRIV GVariant *std_gvar_min_max_step_array(const double a[3]);
7bc3cfe6 1021SR_PRIV GVariant *std_gvar_min_max_step_thresholds(const double dmin, const double dmax, const double dstep);
db944f16 1022
a162eeb2 1023SR_PRIV GVariant *std_gvar_tuple_u64(uint64_t low, uint64_t high);
43995cda 1024SR_PRIV GVariant *std_gvar_tuple_double(double low, double high);
a162eeb2 1025
769561cb
UH
1026SR_PRIV GVariant *std_gvar_array_i32(const int32_t a[], unsigned int n);
1027SR_PRIV GVariant *std_gvar_array_u32(const uint32_t a[], unsigned int n);
1028SR_PRIV GVariant *std_gvar_array_u64(const uint64_t a[], unsigned int n);
70635036 1029SR_PRIV GVariant *std_gvar_array_str(const char *a[], unsigned int n);
db944f16 1030
94e64a0b 1031SR_PRIV GVariant *std_gvar_thresholds(const double a[][2], unsigned int n);
9fb9afb5 1032
697fb6dd
UH
1033SR_PRIV int std_str_idx(GVariant *data, const char *a[], unsigned int n);
1034SR_PRIV int std_u64_idx(GVariant *data, const uint64_t a[], unsigned int n);
1035SR_PRIV int std_u8_idx(GVariant *data, const uint8_t a[], unsigned int n);
1036
1037SR_PRIV int std_str_idx_s(const char *s, const char *a[], unsigned int n);
1038SR_PRIV int std_u8_idx_s(uint8_t b, const uint8_t a[], unsigned int n);
1039
1040SR_PRIV int std_u64_tuple_idx(GVariant *data, const uint64_t a[][2], unsigned int n);
1041SR_PRIV int std_double_tuple_idx(GVariant *data, const double a[][2], unsigned int n);
1042SR_PRIV int std_double_tuple_idx_d0(const double d, const double a[][2], unsigned int n);
1043
fcd6a8bd
UH
1044SR_PRIV int std_cg_idx(const struct sr_channel_group *cg, struct sr_channel_group *a[], unsigned int n);
1045
bee24666
DE
1046/*--- resource.c ------------------------------------------------------------*/
1047
7d89fd60
DE
1048SR_PRIV int64_t sr_file_get_size(FILE *file);
1049
bee24666
DE
1050SR_PRIV int sr_resource_open(struct sr_context *ctx,
1051 struct sr_resource *res, int type, const char *name)
1052 G_GNUC_WARN_UNUSED_RESULT;
1053SR_PRIV int sr_resource_close(struct sr_context *ctx,
1054 struct sr_resource *res);
32ba0d80 1055SR_PRIV gssize sr_resource_read(struct sr_context *ctx,
bee24666
DE
1056 const struct sr_resource *res, void *buf, size_t count)
1057 G_GNUC_WARN_UNUSED_RESULT;
1058SR_PRIV void *sr_resource_load(struct sr_context *ctx, int type,
1059 const char *name, size_t *size, size_t max_size)
1060 G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT;
1061
8d558c7a
UH
1062/*--- strutil.c -------------------------------------------------------------*/
1063
1064SR_PRIV int sr_atol(const char *str, long *ret);
1065SR_PRIV int sr_atoi(const char *str, int *ret);
1066SR_PRIV int sr_atod(const char *str, double *ret);
1067SR_PRIV int sr_atof(const char *str, float *ret);
4f0463a0 1068SR_PRIV int sr_atod_ascii(const char *str, double *ret);
9806c2d5 1069SR_PRIV int sr_atof_ascii(const char *str, float *ret);
8d558c7a 1070
d8bc7ca3
GS
1071SR_PRIV GString *sr_hexdump_new(const uint8_t *data, const size_t len);
1072SR_PRIV void sr_hexdump_free(GString *s);
1073
ac136b57
BV
1074/*--- soft-trigger.c --------------------------------------------------------*/
1075
1076struct soft_trigger_logic {
1077 const struct sr_dev_inst *sdi;
1078 const struct sr_trigger *trigger;
1079 int count;
1080 int unitsize;
1081 int cur_stage;
1082 uint8_t *prev_sample;
fe5a7355
AJ
1083 uint8_t *pre_trigger_buffer;
1084 uint8_t *pre_trigger_head;
1085 int pre_trigger_size;
1086 int pre_trigger_fill;
ac136b57
BV
1087};
1088
d1078180 1089SR_PRIV int logic_channel_unitsize(GSList *channels);
ac136b57 1090SR_PRIV struct soft_trigger_logic *soft_trigger_logic_new(
fe5a7355
AJ
1091 const struct sr_dev_inst *sdi, struct sr_trigger *trigger,
1092 int pre_trigger_samples);
ac136b57
BV
1093SR_PRIV void soft_trigger_logic_free(struct soft_trigger_logic *st);
1094SR_PRIV int soft_trigger_logic_check(struct soft_trigger_logic *st, uint8_t *buf,
fe5a7355 1095 int len, int *pre_trigger_samples);
ac136b57 1096
fcfa36fd 1097/*--- serial.c --------------------------------------------------------------*/
058b7035 1098
1df81f4b 1099#ifdef HAVE_SERIAL_COMM
a54dd31e
UH
1100enum {
1101 SERIAL_RDWR = 1,
1102 SERIAL_RDONLY = 2,
a54dd31e
UH
1103};
1104
144f6660 1105typedef gboolean (*packet_valid_callback)(const uint8_t *buf);
766456be 1106
ae4c1fb6
GS
1107typedef GSList *(*sr_ser_list_append_t)(GSList *devs, const char *name,
1108 const char *desc);
1109typedef GSList *(*sr_ser_find_append_t)(GSList *devs, const char *name);
1110
299bdb24
BV
1111SR_PRIV int serial_open(struct sr_serial_dev_inst *serial, int flags);
1112SR_PRIV int serial_close(struct sr_serial_dev_inst *serial);
1113SR_PRIV int serial_flush(struct sr_serial_dev_inst *serial);
bce75f94 1114SR_PRIV int serial_drain(struct sr_serial_dev_inst *serial);
8c3df6e5 1115SR_PRIV size_t serial_has_receive_data(struct sr_serial_dev_inst *serial);
9a474211 1116SR_PRIV int serial_write_blocking(struct sr_serial_dev_inst *serial,
eead2782 1117 const void *buf, size_t count, unsigned int timeout_ms);
9a474211
ML
1118SR_PRIV int serial_write_nonblocking(struct sr_serial_dev_inst *serial,
1119 const void *buf, size_t count);
9a474211 1120SR_PRIV int serial_read_blocking(struct sr_serial_dev_inst *serial, void *buf,
eead2782 1121 size_t count, unsigned int timeout_ms);
9a474211
ML
1122SR_PRIV int serial_read_nonblocking(struct sr_serial_dev_inst *serial, void *buf,
1123 size_t count);
299bdb24 1124SR_PRIV int serial_set_params(struct sr_serial_dev_inst *serial, int baudrate,
71caaad4 1125 int bits, int parity, int stopbits, int flowcontrol, int rts, int dtr);
299bdb24
BV
1126SR_PRIV int serial_set_paramstr(struct sr_serial_dev_inst *serial,
1127 const char *paramstr);
1128SR_PRIV int serial_readline(struct sr_serial_dev_inst *serial, char **buf,
1129 int *buflen, gint64 timeout_ms);
766456be
UH
1130SR_PRIV int serial_stream_detect(struct sr_serial_dev_inst *serial,
1131 uint8_t *buf, size_t *buflen,
144f6660
UH
1132 size_t packet_size,
1133 packet_valid_callback is_valid,
766456be 1134 uint64_t timeout_ms, int baudrate);
1bd9e678
DJ
1135SR_PRIV int sr_serial_extract_options(GSList *options, const char **serial_device,
1136 const char **serial_options);
102f1239
BV
1137SR_PRIV int serial_source_add(struct sr_session *session,
1138 struct sr_serial_dev_inst *serial, int events, int timeout,
1139 sr_receive_data_callback cb, void *cb_data);
1140SR_PRIV int serial_source_remove(struct sr_session *session,
1141 struct sr_serial_dev_inst *serial);
b541f837 1142SR_PRIV GSList *sr_serial_find_usb(uint16_t vendor_id, uint16_t product_id);
c5cfc735 1143SR_PRIV int serial_timeout(struct sr_serial_dev_inst *port, int num_bytes);
ae4c1fb6 1144
ad5aa993
GS
1145SR_PRIV void sr_ser_discard_queued_data(struct sr_serial_dev_inst *serial);
1146SR_PRIV size_t sr_ser_has_queued_data(struct sr_serial_dev_inst *serial);
1147SR_PRIV void sr_ser_queue_rx_data(struct sr_serial_dev_inst *serial,
1148 const uint8_t *data, size_t len);
1149SR_PRIV size_t sr_ser_unqueue_rx_data(struct sr_serial_dev_inst *serial,
1150 uint8_t *data, size_t len);
1151
a7b8692e
GS
1152struct ser_lib_functions {
1153 int (*open)(struct sr_serial_dev_inst *serial, int flags);
1154 int (*close)(struct sr_serial_dev_inst *serial);
1155 int (*flush)(struct sr_serial_dev_inst *serial);
1156 int (*drain)(struct sr_serial_dev_inst *serial);
1157 int (*write)(struct sr_serial_dev_inst *serial,
1158 const void *buf, size_t count,
1159 int nonblocking, unsigned int timeout_ms);
1160 int (*read)(struct sr_serial_dev_inst *serial,
1161 void *buf, size_t count,
1162 int nonblocking, unsigned int timeout_ms);
1163 int (*set_params)(struct sr_serial_dev_inst *serial,
1164 int baudrate, int bits, int parity, int stopbits,
1165 int flowcontrol, int rts, int dtr);
1166 int (*setup_source_add)(struct sr_session *session,
1167 struct sr_serial_dev_inst *serial,
1168 int events, int timeout,
1169 sr_receive_data_callback cb, void *cb_data);
1170 int (*setup_source_remove)(struct sr_session *session,
1171 struct sr_serial_dev_inst *serial);
1172 GSList *(*list)(GSList *list, sr_ser_list_append_t append);
1173 GSList *(*find_usb)(GSList *list, sr_ser_find_append_t append,
1174 uint16_t vendor_id, uint16_t product_id);
1175 int (*get_frame_format)(struct sr_serial_dev_inst *serial,
1176 int *baud, int *bits);
1177 size_t (*get_rx_avail)(struct sr_serial_dev_inst *serial);
1178};
1179extern SR_PRIV struct ser_lib_functions *ser_lib_funcs_libsp;
c4f2dfd0 1180#endif
1483577e 1181
fcfa36fd 1182/*--- ezusb.c ---------------------------------------------------------------*/
058b7035 1183
22b02383 1184#ifdef HAVE_LIBUSB_1_0
1a081ca6 1185SR_PRIV int ezusb_reset(struct libusb_device_handle *hdl, int set_clear);
8e2d6c9d
DE
1186SR_PRIV int ezusb_install_firmware(struct sr_context *ctx, libusb_device_handle *hdl,
1187 const char *name);
1188SR_PRIV int ezusb_upload_firmware(struct sr_context *ctx, libusb_device *dev,
1189 int configuration, const char *name);
22b02383 1190#endif
058b7035 1191
fcfa36fd 1192/*--- usb.c -----------------------------------------------------------------*/
0c632d36
UH
1193
1194#ifdef HAVE_LIBUSB_1_0
7ae6a758 1195SR_PRIV GSList *sr_usb_find(libusb_context *usb_ctx, const char *conn);
0c632d36 1196SR_PRIV int sr_usb_open(libusb_context *usb_ctx, struct sr_usb_dev_inst *usb);
67e95ed3 1197SR_PRIV void sr_usb_close(struct sr_usb_dev_inst *usb);
102f1239
BV
1198SR_PRIV int usb_source_add(struct sr_session *session, struct sr_context *ctx,
1199 int timeout, sr_receive_data_callback cb, void *cb_data);
1200SR_PRIV int usb_source_remove(struct sr_session *session, struct sr_context *ctx);
76bc5f63 1201SR_PRIV int usb_get_port_path(libusb_device *dev, char *path, int path_len);
69f7d9b4
JH
1202SR_PRIV gboolean usb_match_manuf_prod(libusb_device *dev,
1203 const char *manufacturer, const char *product);
0c632d36
UH
1204#endif
1205
7b9d7320 1206
daa39012
AJ
1207/*--- modbus/modbus.c -------------------------------------------------------*/
1208
1209struct sr_modbus_dev_inst {
1210 const char *name;
1211 const char *prefix;
1212 int priv_size;
1213 GSList *(*scan)(int modbusaddr);
1214 int (*dev_inst_new)(void *priv, const char *resource,
1215 char **params, const char *serialcomm, int modbusaddr);
1216 int (*open)(void *priv);
1217 int (*source_add)(struct sr_session *session, void *priv, int events,
1218 int timeout, sr_receive_data_callback cb, void *cb_data);
1219 int (*source_remove)(struct sr_session *session, void *priv);
1220 int (*send)(void *priv, const uint8_t *buffer, int buffer_size);
1221 int (*read_begin)(void *priv, uint8_t *function_code);
1222 int (*read_data)(void *priv, uint8_t *buf, int maxlen);
1223 int (*read_end)(void *priv);
1224 int (*close)(void *priv);
1225 void (*free)(void *priv);
1226 unsigned int read_timeout_ms;
1227 void *priv;
1228};
1229
1230SR_PRIV GSList *sr_modbus_scan(struct drv_context *drvc, GSList *options,
1231 struct sr_dev_inst *(*probe_device)(struct sr_modbus_dev_inst *modbus));
1232SR_PRIV struct sr_modbus_dev_inst *modbus_dev_inst_new(const char *resource,
1233 const char *serialcomm, int modbusaddr);
1234SR_PRIV int sr_modbus_open(struct sr_modbus_dev_inst *modbus);
1235SR_PRIV int sr_modbus_source_add(struct sr_session *session,
1236 struct sr_modbus_dev_inst *modbus, int events, int timeout,
1237 sr_receive_data_callback cb, void *cb_data);
1238SR_PRIV int sr_modbus_source_remove(struct sr_session *session,
1239 struct sr_modbus_dev_inst *modbus);
1240SR_PRIV int sr_modbus_request(struct sr_modbus_dev_inst *modbus,
1241 uint8_t *request, int request_size);
1242SR_PRIV int sr_modbus_reply(struct sr_modbus_dev_inst *modbus,
1243 uint8_t *reply, int reply_size);
1244SR_PRIV int sr_modbus_request_reply(struct sr_modbus_dev_inst *modbus,
1245 uint8_t *request, int request_size,
1246 uint8_t *reply, int reply_size);
1247SR_PRIV int sr_modbus_read_coils(struct sr_modbus_dev_inst *modbus,
1248 int address, int nb_coils, uint8_t *coils);
1249SR_PRIV int sr_modbus_read_holding_registers(struct sr_modbus_dev_inst *modbus,
1250 int address, int nb_registers,
1251 uint16_t *registers);
1252SR_PRIV int sr_modbus_write_coil(struct sr_modbus_dev_inst *modbus,
1253 int address, int value);
1254SR_PRIV int sr_modbus_write_multiple_registers(struct sr_modbus_dev_inst*modbus,
1255 int address, int nb_registers,
1256 uint16_t *registers);
1257SR_PRIV int sr_modbus_close(struct sr_modbus_dev_inst *modbus);
1258SR_PRIV void sr_modbus_free(struct sr_modbus_dev_inst *modbus);
1259
fcfa36fd 1260/*--- dmm/es519xx.c ---------------------------------------------------------*/
c01bdebc 1261
bfb926c1
AJ
1262/**
1263 * All 11-byte es519xx chips repeat each block twice for each conversion cycle
1264 * so always read 2 blocks at a time.
1265 */
1266#define ES519XX_11B_PACKET_SIZE (11 * 2)
72e1672f 1267#define ES519XX_14B_PACKET_SIZE 14
c01bdebc
AJ
1268
1269struct es519xx_info {
1270 gboolean is_judge, is_voltage, is_auto, is_micro, is_current;
1271 gboolean is_milli, is_resistance, is_continuity, is_diode;
1272 gboolean is_frequency, is_rpm, is_capacitance, is_duty_cycle;
1273 gboolean is_temperature, is_celsius, is_fahrenheit;
1274 gboolean is_adp0, is_adp1, is_adp2, is_adp3;
1275 gboolean is_sign, is_batt, is_ol, is_pmax, is_pmin, is_apo;
1276 gboolean is_dc, is_ac, is_vahz, is_min, is_max, is_rel, is_hold;
1277 gboolean is_digit4, is_ul, is_vasel, is_vbar, is_lpf1, is_lpf0, is_rmr;
1278 uint32_t baudrate;
1279 int packet_size;
1280 gboolean alt_functions, fivedigits, clampmeter, selectable_lpf;
8cbf5627 1281 int digits;
c01bdebc
AJ
1282};
1283
72e1672f
UH
1284SR_PRIV gboolean sr_es519xx_2400_11b_packet_valid(const uint8_t *buf);
1285SR_PRIV int sr_es519xx_2400_11b_parse(const uint8_t *buf, float *floatval,
8c677240 1286 struct sr_datafeed_analog *analog, void *info);
2588e50c
AJ
1287SR_PRIV gboolean sr_es519xx_2400_11b_altfn_packet_valid(const uint8_t *buf);
1288SR_PRIV int sr_es519xx_2400_11b_altfn_parse(const uint8_t *buf,
8c677240 1289 float *floatval, struct sr_datafeed_analog *analog, void *info);
72e1672f 1290SR_PRIV gboolean sr_es519xx_19200_11b_5digits_packet_valid(const uint8_t *buf);
93d719cd 1291SR_PRIV int sr_es519xx_19200_11b_5digits_parse(const uint8_t *buf,
8c677240 1292 float *floatval, struct sr_datafeed_analog *analog, void *info);
72e1672f
UH
1293SR_PRIV gboolean sr_es519xx_19200_11b_clamp_packet_valid(const uint8_t *buf);
1294SR_PRIV int sr_es519xx_19200_11b_clamp_parse(const uint8_t *buf,
8c677240 1295 float *floatval, struct sr_datafeed_analog *analog, void *info);
72e1672f
UH
1296SR_PRIV gboolean sr_es519xx_19200_11b_packet_valid(const uint8_t *buf);
1297SR_PRIV int sr_es519xx_19200_11b_parse(const uint8_t *buf, float *floatval,
8c677240 1298 struct sr_datafeed_analog *analog, void *info);
72e1672f
UH
1299SR_PRIV gboolean sr_es519xx_19200_14b_packet_valid(const uint8_t *buf);
1300SR_PRIV int sr_es519xx_19200_14b_parse(const uint8_t *buf, float *floatval,
8c677240 1301 struct sr_datafeed_analog *analog, void *info);
72e1672f
UH
1302SR_PRIV gboolean sr_es519xx_19200_14b_sel_lpf_packet_valid(const uint8_t *buf);
1303SR_PRIV int sr_es519xx_19200_14b_sel_lpf_parse(const uint8_t *buf,
8c677240 1304 float *floatval, struct sr_datafeed_analog *analog, void *info);
c01bdebc 1305
fcfa36fd 1306/*--- dmm/fs9922.c ----------------------------------------------------------*/
79081ec8 1307
913abe83
UH
1308#define FS9922_PACKET_SIZE 14
1309
1310struct fs9922_info {
1311 gboolean is_auto, is_dc, is_ac, is_rel, is_hold, is_bpn, is_z1, is_z2;
1312 gboolean is_max, is_min, is_apo, is_bat, is_nano, is_z3, is_micro;
1313 gboolean is_milli, is_kilo, is_mega, is_beep, is_diode, is_percent;
1314 gboolean is_z4, is_volt, is_ampere, is_ohm, is_hfe, is_hertz, is_farad;
1315 gboolean is_celsius, is_fahrenheit;
1316 int bargraph_sign, bargraph_value;
1317};
1318
913abe83
UH
1319SR_PRIV gboolean sr_fs9922_packet_valid(const uint8_t *buf);
1320SR_PRIV int sr_fs9922_parse(const uint8_t *buf, float *floatval,
8c677240
UH
1321 struct sr_datafeed_analog *analog, void *info);
1322SR_PRIV void sr_fs9922_z1_diode(struct sr_datafeed_analog *analog, void *info);
79081ec8 1323
fcfa36fd 1324/*--- dmm/fs9721.c ----------------------------------------------------------*/
6c701476 1325
8c1adf37
UH
1326#define FS9721_PACKET_SIZE 14
1327
1328struct fs9721_info {
1329 gboolean is_ac, is_dc, is_auto, is_rs232, is_micro, is_nano, is_kilo;
1330 gboolean is_diode, is_milli, is_percent, is_mega, is_beep, is_farad;
1331 gboolean is_ohm, is_rel, is_hold, is_ampere, is_volt, is_hz, is_bat;
1332 gboolean is_c2c1_11, is_c2c1_10, is_c2c1_01, is_c2c1_00, is_sign;
1333};
1334
8c1adf37
UH
1335SR_PRIV gboolean sr_fs9721_packet_valid(const uint8_t *buf);
1336SR_PRIV int sr_fs9721_parse(const uint8_t *buf, float *floatval,
8c677240
UH
1337 struct sr_datafeed_analog *analog, void *info);
1338SR_PRIV void sr_fs9721_00_temp_c(struct sr_datafeed_analog *analog, void *info);
1339SR_PRIV void sr_fs9721_01_temp_c(struct sr_datafeed_analog *analog, void *info);
1340SR_PRIV void sr_fs9721_10_temp_c(struct sr_datafeed_analog *analog, void *info);
1341SR_PRIV void sr_fs9721_01_10_temp_f_c(struct sr_datafeed_analog *analog, void *info);
1342SR_PRIV void sr_fs9721_max_c_min(struct sr_datafeed_analog *analog, void *info);
dcd212f7
VV
1343
1344/*--- dmm/ms2115b.c ---------------------------------------------------------*/
1345
1346#define MS2115B_PACKET_SIZE 9
1347
1348enum ms2115b_display {
1349 MS2115B_DISPLAY_MAIN,
1350 MS2115B_DISPLAY_SUB,
1351 MS2115B_DISPLAY_COUNT,
1352};
1353
1354struct ms2115b_info {
1355 /* Selected channel. */
1356 size_t ch_idx;
1357 gboolean is_ac, is_dc, is_auto;
1358 gboolean is_diode, is_beep, is_farad;
1359 gboolean is_ohm, is_ampere, is_volt, is_hz;
1360 gboolean is_duty_cycle, is_percent;
1361};
1362
1363extern SR_PRIV const char *ms2115b_channel_formats[];
1364SR_PRIV gboolean sr_ms2115b_packet_valid(const uint8_t *buf);
1365SR_PRIV int sr_ms2115b_parse(const uint8_t *buf, float *floatval,
1366 struct sr_datafeed_analog *analog, void *info);
6c701476 1367
fcfa36fd 1368/*--- dmm/ms8250d.c ---------------------------------------------------------*/
67070942
M
1369
1370#define MS8250D_PACKET_SIZE 18
1371
1372struct ms8250d_info {
1373 gboolean is_ac, is_dc, is_auto, is_rs232, is_micro, is_nano, is_kilo;
1374 gboolean is_diode, is_milli, is_percent, is_mega, is_beep, is_farad;
1375 gboolean is_ohm, is_rel, is_hold, is_ampere, is_volt, is_hz, is_bat;
1376 gboolean is_ncv, is_min, is_max, is_sign, is_autotimer;
1377};
1378
1379SR_PRIV gboolean sr_ms8250d_packet_valid(const uint8_t *buf);
1380SR_PRIV int sr_ms8250d_parse(const uint8_t *buf, float *floatval,
1381 struct sr_datafeed_analog *analog, void *info);
1382
fcfa36fd 1383/*--- dmm/dtm0660.c ---------------------------------------------------------*/
eed3dec8
MG
1384
1385#define DTM0660_PACKET_SIZE 15
1386
1387struct dtm0660_info {
1388 gboolean is_ac, is_dc, is_auto, is_rs232, is_micro, is_nano, is_kilo;
1389 gboolean is_diode, is_milli, is_percent, is_mega, is_beep, is_farad;
1390 gboolean is_ohm, is_rel, is_hold, is_ampere, is_volt, is_hz, is_bat;
1391 gboolean is_degf, is_degc, is_c2c1_01, is_c2c1_00, is_apo, is_min;
1392 gboolean is_minmax, is_max, is_sign;
1393};
1394
1395SR_PRIV gboolean sr_dtm0660_packet_valid(const uint8_t *buf);
1396SR_PRIV int sr_dtm0660_parse(const uint8_t *buf, float *floatval,
8c677240 1397 struct sr_datafeed_analog *analog, void *info);
eed3dec8 1398
fcfa36fd 1399/*--- dmm/m2110.c -----------------------------------------------------------*/
825da8b2
MH
1400
1401#define BBCGM_M2110_PACKET_SIZE 9
1402
9d12555f
UH
1403/* Dummy info struct. The parser does not use it. */
1404struct m2110_info { int dummy; };
1405
825da8b2
MH
1406SR_PRIV gboolean sr_m2110_packet_valid(const uint8_t *buf);
1407SR_PRIV int sr_m2110_parse(const uint8_t *buf, float *floatval,
8c677240 1408 struct sr_datafeed_analog *analog, void *info);
825da8b2 1409
fcfa36fd 1410/*--- dmm/metex14.c ---------------------------------------------------------*/
ac913e5c
UH
1411
1412#define METEX14_PACKET_SIZE 14
1413
1414struct metex14_info {
556a926d 1415 size_t ch_idx;
ac913e5c
UH
1416 gboolean is_ac, is_dc, is_resistance, is_capacity, is_temperature;
1417 gboolean is_diode, is_frequency, is_ampere, is_volt, is_farad;
7fb4ff02
FS
1418 gboolean is_hertz, is_ohm, is_celsius, is_fahrenheit, is_watt;
1419 gboolean is_pico, is_nano, is_micro, is_milli, is_kilo, is_mega;
fd8dc1db 1420 gboolean is_gain, is_decibel, is_power, is_decibel_mw, is_power_factor;
7fb4ff02 1421 gboolean is_hfe, is_unitless, is_logic, is_min, is_max, is_avg;
ac913e5c
UH
1422};
1423
1df81f4b 1424#ifdef HAVE_SERIAL_COMM
ce3777ad 1425SR_PRIV int sr_metex14_packet_request(struct sr_serial_dev_inst *serial);
c4f2dfd0 1426#endif
ac913e5c
UH
1427SR_PRIV gboolean sr_metex14_packet_valid(const uint8_t *buf);
1428SR_PRIV int sr_metex14_parse(const uint8_t *buf, float *floatval,
8c677240 1429 struct sr_datafeed_analog *analog, void *info);
556a926d
GS
1430SR_PRIV gboolean sr_metex14_4packets_valid(const uint8_t *buf);
1431SR_PRIV int sr_metex14_4packets_parse(const uint8_t *buf, float *floatval,
1432 struct sr_datafeed_analog *analog, void *info);
ac913e5c 1433
fcfa36fd 1434/*--- dmm/rs9lcd.c ----------------------------------------------------------*/
05f134ab 1435
21829e67 1436#define RS9LCD_PACKET_SIZE 9
05f134ab 1437
e7ed87a4 1438/* Dummy info struct. The parser does not use it. */
bf6f8399 1439struct rs9lcd_info { int dummy; };
e7ed87a4 1440
05f134ab
AG
1441SR_PRIV gboolean sr_rs9lcd_packet_valid(const uint8_t *buf);
1442SR_PRIV int sr_rs9lcd_parse(const uint8_t *buf, float *floatval,
8c677240 1443 struct sr_datafeed_analog *analog, void *info);
05f134ab 1444
fcfa36fd 1445/*--- dmm/bm25x.c -----------------------------------------------------------*/
a24c3f4a
JH
1446
1447#define BRYMEN_BM25X_PACKET_SIZE 15
1448
1449/* Dummy info struct. The parser does not use it. */
1450struct bm25x_info { int dummy; };
1451
1452SR_PRIV gboolean sr_brymen_bm25x_packet_valid(const uint8_t *buf);
1453SR_PRIV int sr_brymen_bm25x_parse(const uint8_t *buf, float *floatval,
8c677240 1454 struct sr_datafeed_analog *analog, void *info);
a24c3f4a 1455
fcfa36fd 1456/*--- dmm/ut71x.c -----------------------------------------------------------*/
626027df
UH
1457
1458#define UT71X_PACKET_SIZE 11
1459
1460struct ut71x_info {
1461 gboolean is_voltage, is_resistance, is_capacitance, is_temperature;
1462 gboolean is_celsius, is_fahrenheit, is_current, is_continuity;
1463 gboolean is_diode, is_frequency, is_duty_cycle, is_dc, is_ac;
1464 gboolean is_auto, is_manual, is_sign, is_power, is_loop_current;
1465};
1466
1467SR_PRIV gboolean sr_ut71x_packet_valid(const uint8_t *buf);
1468SR_PRIV int sr_ut71x_parse(const uint8_t *buf, float *floatval,
8c677240 1469 struct sr_datafeed_analog *analog, void *info);
626027df 1470
fcfa36fd 1471/*--- dmm/vc870.c -----------------------------------------------------------*/
c36f78f7
UH
1472
1473#define VC870_PACKET_SIZE 23
1474
1475struct vc870_info {
1476 gboolean is_voltage, is_dc, is_ac, is_temperature, is_resistance;
1477 gboolean is_continuity, is_capacitance, is_diode, is_loop_current;
1478 gboolean is_current, is_micro, is_milli, is_power;
ee2e9be2 1479 gboolean is_power_factor_freq, is_power_apparent_power, is_v_a_rms_value;
c36f78f7
UH
1480 gboolean is_sign2, is_sign1, is_batt, is_ol1, is_max, is_min;
1481 gboolean is_maxmin, is_rel, is_ol2, is_open, is_manu, is_hold;
1482 gboolean is_light, is_usb, is_warning, is_auto_power, is_misplug_warn;
1483 gboolean is_lo, is_hi, is_open2;
1484
3591481e 1485 gboolean is_frequency, is_dual_display, is_auto;
c36f78f7
UH
1486};
1487
1488SR_PRIV gboolean sr_vc870_packet_valid(const uint8_t *buf);
1489SR_PRIV int sr_vc870_parse(const uint8_t *buf, float *floatval,
8c677240 1490 struct sr_datafeed_analog *analog, void *info);
c36f78f7 1491
fcfa36fd 1492/*--- dmm/vc96.c ------------------------------------------------------------*/
9456d636
MS
1493
1494#define VC96_PACKET_SIZE 13
1495
1496struct vc96_info {
1497 size_t ch_idx;
1498 gboolean is_ac, is_dc, is_resistance, is_diode, is_ampere, is_volt;
1499 gboolean is_ohm, is_micro, is_milli, is_kilo, is_mega, is_hfe;
1500 gboolean is_unitless;
1501};
1502
1503SR_PRIV gboolean sr_vc96_packet_valid(const uint8_t *buf);
1504SR_PRIV int sr_vc96_parse(const uint8_t *buf, float *floatval,
1505 struct sr_datafeed_analog *analog, void *info);
1506
fcfa36fd 1507/*--- lcr/es51919.c ---------------------------------------------------------*/
6bcb3ee8
JH
1508
1509SR_PRIV void es51919_serial_clean(void *priv);
1510SR_PRIV struct sr_dev_inst *es51919_serial_scan(GSList *options,
1511 const char *vendor,
1512 const char *model);
1513SR_PRIV int es51919_serial_config_get(uint32_t key, GVariant **data,
1514 const struct sr_dev_inst *sdi,
1515 const struct sr_channel_group *cg);
1516SR_PRIV int es51919_serial_config_set(uint32_t key, GVariant *data,
1517 const struct sr_dev_inst *sdi,
1518 const struct sr_channel_group *cg);
1519SR_PRIV int es51919_serial_config_list(uint32_t key, GVariant **data,
1520 const struct sr_dev_inst *sdi,
1521 const struct sr_channel_group *cg);
695dc859
UH
1522SR_PRIV int es51919_serial_acquisition_start(const struct sr_dev_inst *sdi);
1523SR_PRIV int es51919_serial_acquisition_stop(struct sr_dev_inst *sdi);
6bcb3ee8 1524
fcfa36fd 1525/*--- dmm/ut372.c -----------------------------------------------------------*/
f3cde309
ML
1526
1527#define UT372_PACKET_SIZE 27
1528
1529struct ut372_info {
1530 int dummy;
1531};
1532
1533SR_PRIV gboolean sr_ut372_packet_valid(const uint8_t *buf);
1534SR_PRIV int sr_ut372_parse(const uint8_t *buf, float *floatval,
8c677240 1535 struct sr_datafeed_analog *analog, void *info);
f3cde309 1536
fcfa36fd 1537/*--- dmm/asycii.c ----------------------------------------------------------*/
4ba4d52a
GS
1538
1539#define ASYCII_PACKET_SIZE 16
1540
1541struct asycii_info {
1542 gboolean is_ac, is_dc, is_ac_and_dc;
1543 gboolean is_resistance, is_capacitance, is_diode, is_gain;
1544 gboolean is_frequency, is_duty_cycle, is_duty_pos, is_duty_neg;
1545 gboolean is_pulse_width, is_period_pos, is_period_neg;
1546 gboolean is_pulse_count, is_count_pos, is_count_neg;
1547 gboolean is_ampere, is_volt, is_volt_ampere, is_farad, is_ohm;
1548 gboolean is_hertz, is_percent, is_seconds, is_decibel;
1549 gboolean is_pico, is_nano, is_micro, is_milli, is_kilo, is_mega;
1550 gboolean is_unitless;
1551 gboolean is_peak_min, is_peak_max;
1552 gboolean is_invalid;
1553};
1554
1df81f4b 1555#ifdef HAVE_SERIAL_COMM
4ba4d52a
GS
1556SR_PRIV int sr_asycii_packet_request(struct sr_serial_dev_inst *serial);
1557#endif
1558SR_PRIV gboolean sr_asycii_packet_valid(const uint8_t *buf);
1559SR_PRIV int sr_asycii_parse(const uint8_t *buf, float *floatval,
1560 struct sr_datafeed_analog *analog, void *info);
1561
fcfa36fd 1562/*--- dmm/eev121gw.c --------------------------------------------------------*/
1c3098aa
GS
1563
1564#define EEV121GW_PACKET_SIZE 19
1565
1566enum eev121gw_display {
1567 EEV121GW_DISPLAY_MAIN,
1568 EEV121GW_DISPLAY_SUB,
1569 EEV121GW_DISPLAY_BAR,
1570 EEV121GW_DISPLAY_COUNT,
1571};
1572
1573struct eev121gw_info {
1574 /* Selected channel. */
1575 size_t ch_idx;
1576 /*
1577 * Measured value, number and sign/overflow flags, scale factor
1578 * and significant digits.
1579 */
1580 uint32_t uint_value;
1581 gboolean is_ofl, is_neg;
1582 int factor, digits;
1583 /* Currently active mode (meter's function). */
1584 gboolean is_ac, is_dc, is_voltage, is_current, is_power, is_gain;
1585 gboolean is_resistance, is_capacitance, is_diode, is_temperature;
1586 gboolean is_continuity, is_frequency, is_period, is_duty_cycle;
1587 /* Quantities associated with mode/function. */
1588 gboolean is_ampere, is_volt, is_volt_ampere, is_dbm;
1589 gboolean is_ohm, is_farad, is_celsius, is_fahrenheit;
1590 gboolean is_hertz, is_seconds, is_percent, is_loop_current;
1591 gboolean is_unitless, is_logic;
1592 /* Other indicators. */
1593 gboolean is_min, is_max, is_avg, is_1ms_peak, is_rel, is_hold;
1594 gboolean is_low_pass, is_mem, is_bt, is_auto_range, is_test;
1595 gboolean is_auto_poweroff, is_low_batt;
1596};
1597
015df4ae 1598extern SR_PRIV const char *eev121gw_channel_formats[];
1c3098aa
GS
1599SR_PRIV gboolean sr_eev121gw_packet_valid(const uint8_t *buf);
1600SR_PRIV int sr_eev121gw_parse(const uint8_t *buf, float *floatval,
1601 struct sr_datafeed_analog *analog, void *info);
1602SR_PRIV int sr_eev121gw_3displays_parse(const uint8_t *buf, float *floatval,
1603 struct sr_datafeed_analog *analog, void *info);
1604
fcfa36fd 1605/*--- scale/kern.c ----------------------------------------------------------*/
e5d953b5
UH
1606
1607struct kern_info {
1608 gboolean is_gram, is_carat, is_ounce, is_pound, is_troy_ounce;
1609 gboolean is_pennyweight, is_grain, is_tael, is_momme, is_tola;
1610 gboolean is_percentage, is_piece, is_unstable, is_stable, is_error;
1611 int buflen;
1612};
1613
1614SR_PRIV gboolean sr_kern_packet_valid(const uint8_t *buf);
1615SR_PRIV int sr_kern_parse(const uint8_t *buf, float *floatval,
563ba4a5 1616 struct sr_datafeed_analog *analog, void *info);
e5d953b5 1617
aea4e458
LPC
1618/*--- sw_limits.c -----------------------------------------------------------*/
1619
1620struct sr_sw_limits {
1621 uint64_t limit_samples;
1622 uint64_t limit_msec;
1623 uint64_t samples_read;
1624 uint64_t start_time;
1625};
1626
1627SR_PRIV int sr_sw_limits_config_get(struct sr_sw_limits *limits, uint32_t key,
1628 GVariant **data);
1629SR_PRIV int sr_sw_limits_config_set(struct sr_sw_limits *limits, uint32_t key,
1630 GVariant *data);
1631SR_PRIV void sr_sw_limits_acquisition_start(struct sr_sw_limits *limits);
1632SR_PRIV gboolean sr_sw_limits_check(struct sr_sw_limits *limits);
1633SR_PRIV void sr_sw_limits_update_samples_read(struct sr_sw_limits *limits,
1634 uint64_t samples_read);
1635SR_PRIV void sr_sw_limits_init(struct sr_sw_limits *limits);
1636
1483577e 1637#endif