]> sigrok.org Git - libsigrok.git/blame - src/libsigrok-internal.h
serial_bt, bluez: rework diag in BLE reception, accept zero length data
[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
a5827886
UH
20#ifndef LIBSIGROK_LIBSIGROK_INTERNAL_H
21#define LIBSIGROK_LIBSIGROK_INTERNAL_H
1483577e 22
1df81f4b
GS
23#include "config.h"
24
cc8a7d25 25#include <glib.h>
4417074c
GS
26#ifdef HAVE_LIBHIDAPI
27#include <hidapi.h>
28#endif
c4f2dfd0 29#ifdef HAVE_LIBSERIALPORT
dc991353 30#include <libserialport.h>
c4f2dfd0 31#endif
fdcdfe53
GS
32#ifdef HAVE_LIBUSB_1_0
33#include <libusb.h>
34#endif
e1a712ca
GS
35#ifdef HAVE_LIBFTDI
36#include <ftdi.h>
37#endif
fdcdfe53 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
6cfc6c5c
UH
62#ifndef G_SOURCE_FUNC
63#define G_SOURCE_FUNC(f) ((GSourceFunc) (void (*)(void)) (f)) /* Since 2.58. */
64#endif
65
66#define SR_RECEIVE_DATA_CALLBACK(f) \
67 ((sr_receive_data_callback) (void (*)(void)) (f))
68
a4f9c35b 69/**
5bf0dd6a 70 * Read a 8 bits unsigned integer out of memory.
a4f9c35b 71 * @param x a pointer to the input memory
5bf0dd6a 72 * @return the corresponding unsigned integer
a4f9c35b 73 */
f1833600
GS
74static inline uint8_t read_u8(const uint8_t *p)
75{
76 return p[0];
77}
78#define R8(x) read_u8((const uint8_t *)(x))
a4f9c35b 79
e4bcc63d
GS
80/**
81 * Read an 8 bits signed integer out of memory.
82 * @param x a pointer to the input memory
83 * @return the corresponding signed integer
84 */
85static inline int8_t read_i8(const uint8_t *p)
86{
87 return (int8_t)p[0];
88}
89
e28ef28a 90/**
5bf0dd6a 91 * Read a 16 bits big endian unsigned integer out of memory.
e28ef28a 92 * @param x a pointer to the input memory
5bf0dd6a 93 * @return the corresponding unsigned integer
e28ef28a 94 */
f1833600
GS
95static inline uint16_t read_u16be(const uint8_t *p)
96{
97 uint16_t u;
98
99 u = 0;
100 u <<= 8; u |= p[0];
101 u <<= 8; u |= p[1];
102
103 return u;
104}
105#define RB16(x) read_u16be((const uint8_t *)(x))
e28ef28a
AJ
106
107/**
5bf0dd6a 108 * Read a 16 bits little endian unsigned integer out of memory.
e28ef28a 109 * @param x a pointer to the input memory
5bf0dd6a 110 * @return the corresponding unsigned integer
e28ef28a 111 */
f1833600
GS
112static inline uint16_t read_u16le(const uint8_t *p)
113{
114 uint16_t u;
115
116 u = 0;
117 u <<= 8; u |= p[1];
118 u <<= 8; u |= p[0];
119
120 return u;
121}
122#define RL16(x) read_u16le((const uint8_t *)(x))
e28ef28a 123
4d376e08
SB
124/**
125 * Read a 16 bits big endian signed integer out of memory.
126 * @param x a pointer to the input memory
127 * @return the corresponding signed integer
128 */
f1833600
GS
129static inline int16_t read_i16be(const uint8_t *p)
130{
131 uint16_t u;
132 int16_t i;
133
134 u = read_u16be(p);
135 i = (int16_t)u;
136
137 return i;
138}
139#define RB16S(x) read_i16be((const uint8_t *)(x))
4d376e08 140
e28ef28a 141/**
5bf0dd6a 142 * Read a 16 bits little endian signed integer out of memory.
e28ef28a 143 * @param x a pointer to the input memory
5bf0dd6a
BV
144 * @return the corresponding signed integer
145 */
f1833600
GS
146static inline int16_t read_i16le(const uint8_t *p)
147{
148 uint16_t u;
149 int16_t i;
150
151 u = read_u16le(p);
152 i = (int16_t)u;
153
154 return i;
155}
156#define RL16S(x) read_i16le((const uint8_t *)(x))
5bf0dd6a 157
080b6bcf
GS
158/**
159 * Read a 24 bits little endian unsigned integer out of memory.
160 * @param x a pointer to the input memory
161 * @return the corresponding unsigned integer
162 */
163static inline uint32_t read_u24le(const uint8_t *p)
164{
165 uint32_t u;
166
167 u = 0;
168 u <<= 8; u |= p[2];
169 u <<= 8; u |= p[1];
170 u <<= 8; u |= p[0];
171
172 return u;
173}
174
5bf0dd6a
BV
175/**
176 * Read a 32 bits big endian unsigned integer out of memory.
177 * @param x a pointer to the input memory
178 * @return the corresponding unsigned integer
e28ef28a 179 */
f1833600
GS
180static inline uint32_t read_u32be(const uint8_t *p)
181{
182 uint32_t u;
183
184 u = 0;
185 u <<= 8; u |= p[0];
186 u <<= 8; u |= p[1];
187 u <<= 8; u |= p[2];
188 u <<= 8; u |= p[3];
189
190 return u;
191}
192#define RB32(x) read_u32be((const uint8_t *)(x))
e28ef28a
AJ
193
194/**
5bf0dd6a 195 * Read a 32 bits little endian unsigned integer out of memory.
e28ef28a 196 * @param x a pointer to the input memory
5bf0dd6a 197 * @return the corresponding unsigned integer
e28ef28a 198 */
f1833600
GS
199static inline uint32_t read_u32le(const uint8_t *p)
200{
201 uint32_t u;
202
203 u = 0;
204 u <<= 8; u |= p[3];
205 u <<= 8; u |= p[2];
206 u <<= 8; u |= p[1];
207 u <<= 8; u |= p[0];
208
209 return u;
210}
211#define RL32(x) read_u32le((const uint8_t *)(x))
e28ef28a 212
4d376e08
SB
213/**
214 * Read a 32 bits big endian signed integer out of memory.
215 * @param x a pointer to the input memory
216 * @return the corresponding signed integer
217 */
f1833600
GS
218static inline int32_t read_i32be(const uint8_t *p)
219{
220 uint32_t u;
221 int32_t i;
222
223 u = read_u32be(p);
224 i = (int32_t)u;
225
226 return i;
227}
228#define RB32S(x) read_i32be((const uint8_t *)(x))
4d376e08 229
ea2d6d99 230/**
5bf0dd6a
BV
231 * Read a 32 bits little endian signed integer out of memory.
232 * @param x a pointer to the input memory
233 * @return the corresponding signed integer
234 */
f1833600
GS
235static inline int32_t read_i32le(const uint8_t *p)
236{
237 uint32_t u;
238 int32_t i;
239
240 u = read_u32le(p);
241 i = (int32_t)u;
242
243 return i;
244}
245#define RL32S(x) read_i32le((const uint8_t *)(x))
5bf0dd6a 246
17b93fd7
TS
247/**
248 * Read a 64 bits big endian unsigned integer out of memory.
249 * @param x a pointer to the input memory
250 * @return the corresponding unsigned integer
251 */
f1833600
GS
252static inline uint64_t read_u64be(const uint8_t *p)
253{
254 uint64_t u;
255
256 u = 0;
257 u <<= 8; u |= p[0];
258 u <<= 8; u |= p[1];
259 u <<= 8; u |= p[2];
260 u <<= 8; u |= p[3];
261 u <<= 8; u |= p[4];
262 u <<= 8; u |= p[5];
263 u <<= 8; u |= p[6];
264 u <<= 8; u |= p[7];
265
266 return u;
267}
268#define RB64(x) read_u64be((const uint8_t *)(x))
17b93fd7 269
8a66b077
SA
270/**
271 * Read a 64 bits little endian unsigned integer out of memory.
272 * @param x a pointer to the input memory
273 * @return the corresponding unsigned integer
274 */
f1833600
GS
275static inline uint64_t read_u64le(const uint8_t *p)
276{
277 uint64_t u;
278
279 u = 0;
280 u <<= 8; u |= p[7];
281 u <<= 8; u |= p[6];
282 u <<= 8; u |= p[5];
283 u <<= 8; u |= p[4];
284 u <<= 8; u |= p[3];
285 u <<= 8; u |= p[2];
286 u <<= 8; u |= p[1];
287 u <<= 8; u |= p[0];
288
289 return u;
290}
291#define RL64(x) read_u64le((const uint8_t *)(x))
292
293/**
294 * Read a 64 bits big endian signed integer out of memory.
295 * @param x a pointer to the input memory
296 * @return the corresponding unsigned integer
297 */
298static inline int64_t read_i64be(const uint8_t *p)
299{
300 uint64_t u;
301 int64_t i;
302
303 u = read_u64be(p);
304 i = (int64_t)u;
305
306 return i;
307}
308#define RB64S(x) read_i64be((const uint8_t *)(x))
8a66b077
SA
309
310/**
311 * Read a 64 bits little endian signed integer out of memory.
312 * @param x a pointer to the input memory
313 * @return the corresponding unsigned integer
314 */
f1833600
GS
315static inline int64_t read_i64le(const uint8_t *p)
316{
317 uint64_t u;
318 int64_t i;
319
320 u = read_u64le(p);
321 i = (int64_t)u;
322
323 return i;
324}
325#define RL64S(x) read_i64le((const uint8_t *)(x))
8a66b077 326
a2632bca 327/**
daa895cb 328 * Read a 32 bits big endian float out of memory (single precision).
a2632bca
AJ
329 * @param x a pointer to the input memory
330 * @return the corresponding float
331 */
f1833600
GS
332static inline float read_fltbe(const uint8_t *p)
333{
334 /*
335 * Implementor's note: Strictly speaking the "union" trick
336 * is not portable. But this phrase was found to work on the
337 * project's supported platforms, and serve well until a more
338 * appropriate phrase is found.
339 */
340 union { uint32_t u32; float flt; } u;
341 float f;
342
343 u.u32 = read_u32be(p);
344 f = u.flt;
345
346 return f;
347}
348#define RBFL(x) read_fltbe((const uint8_t *)(x))
a2632bca
AJ
349
350/**
daa895cb 351 * Read a 32 bits little endian float out of memory (single precision).
a2632bca
AJ
352 * @param x a pointer to the input memory
353 * @return the corresponding float
354 */
f1833600
GS
355static inline float read_fltle(const uint8_t *p)
356{
357 /*
358 * Implementor's note: Strictly speaking the "union" trick
359 * is not portable. But this phrase was found to work on the
360 * project's supported platforms, and serve well until a more
361 * appropriate phrase is found.
362 */
363 union { uint32_t u32; float flt; } u;
364 float f;
365
366 u.u32 = read_u32le(p);
367 f = u.flt;
368
369 return f;
370}
371#define RLFL(x) read_fltle((const uint8_t *)(x))
a2632bca 372
e4bcc63d
GS
373/**
374 * Read a 64 bits big endian float out of memory (double precision).
375 * @param x a pointer to the input memory
376 * @return the corresponding floating point value
377 */
378static inline double read_dblbe(const uint8_t *p)
379{
380 /*
381 * Implementor's note: Strictly speaking the "union" trick
382 * is not portable. But this phrase was found to work on the
383 * project's supported platforms, and serve well until a more
384 * appropriate phrase is found.
385 */
386 union { uint64_t u64; double flt; } u;
387 double f;
388
389 u.u64 = read_u64be(p);
390 f = u.flt;
391
392 return f;
393}
394
daa895cb
GS
395/**
396 * Read a 64 bits little endian float out of memory (double precision).
397 * @param x a pointer to the input memory
398 * @return the corresponding floating point value
399 */
400static inline double read_dblle(const uint8_t *p)
401{
402 /*
403 * Implementor's note: Strictly speaking the "union" trick
404 * is not portable. But this phrase was found to work on the
405 * project's supported platforms, and serve well until a more
406 * appropriate phrase is found.
407 */
408 union { uint64_t u64; double flt; } u;
409 double f;
410
411 u.u64 = read_u64le(p);
412 f = u.flt;
413
414 return f;
415}
416#define RLDB(x) read_dblle((const uint8_t *)(x))
417
5bf0dd6a
BV
418/**
419 * Write a 8 bits unsigned integer to memory.
ea2d6d99 420 * @param p a pointer to the output memory
5bf0dd6a 421 * @param x the input unsigned integer
ea2d6d99 422 */
f1833600
GS
423static inline void write_u8(uint8_t *p, uint8_t x)
424{
425 p[0] = x;
426}
427#define W8(p, x) write_u8((uint8_t *)(p), (uint8_t)(x))
ea2d6d99
AJ
428
429/**
5bf0dd6a 430 * Write a 16 bits unsigned integer to memory stored as big endian.
ea2d6d99 431 * @param p a pointer to the output memory
5bf0dd6a 432 * @param x the input unsigned integer
ea2d6d99 433 */
f1833600
GS
434static inline void write_u16be(uint8_t *p, uint16_t x)
435{
436 p[1] = x & 0xff; x >>= 8;
437 p[0] = x & 0xff; x >>= 8;
438}
439#define WB16(p, x) write_u16be((uint8_t *)(p), (uint16_t)(x))
ea2d6d99
AJ
440
441/**
5bf0dd6a 442 * Write a 16 bits unsigned integer to memory stored as little endian.
ea2d6d99 443 * @param p a pointer to the output memory
5bf0dd6a 444 * @param x the input unsigned integer
ea2d6d99 445 */
f1833600
GS
446static inline void write_u16le(uint8_t *p, uint16_t x)
447{
448 p[0] = x & 0xff; x >>= 8;
449 p[1] = x & 0xff; x >>= 8;
450}
451#define WL16(p, x) write_u16le((uint8_t *)(p), (uint16_t)(x))
ea2d6d99 452
15526343
GS
453/**
454 * Write a 24 bits unsigned integer to memory stored as little endian.
455 * @param p a pointer to the output memory
456 * @param x the input unsigned integer
457 */
458static inline void write_u24le(uint8_t *p, uint32_t x)
459{
460 p[0] = x & 0xff; x >>= 8;
461 p[1] = x & 0xff; x >>= 8;
462 p[2] = x & 0xff; x >>= 8;
463}
464#define WL24(p, x) write_u24le((uint8_t *)(p), (uint32_t)(x))
465
ea2d6d99 466/**
5bf0dd6a 467 * Write a 32 bits unsigned integer to memory stored as big endian.
ea2d6d99 468 * @param p a pointer to the output memory
5bf0dd6a 469 * @param x the input unsigned integer
ea2d6d99 470 */
f1833600
GS
471static inline void write_u32be(uint8_t *p, uint32_t x)
472{
473 p[3] = x & 0xff; x >>= 8;
474 p[2] = x & 0xff; x >>= 8;
475 p[1] = x & 0xff; x >>= 8;
476 p[0] = x & 0xff; x >>= 8;
477}
478#define WB32(p, x) write_u32be((uint8_t *)(p), (uint32_t)(x))
ea2d6d99
AJ
479
480/**
5bf0dd6a 481 * Write a 32 bits unsigned integer to memory stored as little endian.
ea2d6d99 482 * @param p a pointer to the output memory
5bf0dd6a 483 * @param x the input unsigned integer
ea2d6d99 484 */
f1833600
GS
485static inline void write_u32le(uint8_t *p, uint32_t x)
486{
487 p[0] = x & 0xff; x >>= 8;
488 p[1] = x & 0xff; x >>= 8;
489 p[2] = x & 0xff; x >>= 8;
490 p[3] = x & 0xff; x >>= 8;
491}
492#define WL32(p, x) write_u32le((uint8_t *)(p), (uint32_t)(x))
ea2d6d99 493
15526343
GS
494/**
495 * Write a 40 bits unsigned integer to memory stored as little endian.
496 * @param p a pointer to the output memory
497 * @param x the input unsigned integer
498 */
499static inline void write_u40le(uint8_t *p, uint64_t x)
500{
501 p[0] = x & 0xff; x >>= 8;
502 p[1] = x & 0xff; x >>= 8;
503 p[2] = x & 0xff; x >>= 8;
504 p[3] = x & 0xff; x >>= 8;
505 p[4] = x & 0xff; x >>= 8;
506}
507#define WL40(p, x) write_u40le((uint8_t *)(p), (uint64_t)(x))
508
797c8d90
GS
509/**
510 * Write a 48 bits unsigned integer to memory stored as little endian.
511 * @param p a pointer to the output memory
512 * @param x the input unsigned integer
513 */
514static inline void write_u48le(uint8_t *p, uint64_t x)
515{
516 p[0] = x & 0xff; x >>= 8;
517 p[1] = x & 0xff; x >>= 8;
518 p[2] = x & 0xff; x >>= 8;
519 p[3] = x & 0xff; x >>= 8;
520 p[4] = x & 0xff; x >>= 8;
521 p[5] = x & 0xff; x >>= 8;
522}
523#define WL48(p, x) write_u48le((uint8_t *)(p), (uint64_t)(x))
524
efce57da
GS
525/**
526 * Write a 64 bits unsigned integer to memory stored as big endian.
527 * @param p a pointer to the output memory
528 * @param x the input unsigned integer
529 */
530static inline void write_u64be(uint8_t *p, uint64_t x)
531{
532 p[7] = x & 0xff; x >>= 8;
533 p[6] = x & 0xff; x >>= 8;
534 p[5] = x & 0xff; x >>= 8;
535 p[4] = x & 0xff; x >>= 8;
536 p[3] = x & 0xff; x >>= 8;
537 p[2] = x & 0xff; x >>= 8;
538 p[1] = x & 0xff; x >>= 8;
539 p[0] = x & 0xff; x >>= 8;
540}
541
daa895cb
GS
542/**
543 * Write a 64 bits unsigned integer to memory stored as little endian.
544 * @param p a pointer to the output memory
545 * @param x the input unsigned integer
546 */
547static inline void write_u64le(uint8_t *p, uint64_t x)
548{
549 p[0] = x & 0xff; x >>= 8;
550 p[1] = x & 0xff; x >>= 8;
551 p[2] = x & 0xff; x >>= 8;
552 p[3] = x & 0xff; x >>= 8;
553 p[4] = x & 0xff; x >>= 8;
554 p[5] = x & 0xff; x >>= 8;
555 p[6] = x & 0xff; x >>= 8;
556 p[7] = x & 0xff; x >>= 8;
557}
558#define WL64(p, x) write_u64le((uint8_t *)(p), (uint64_t)(x))
559
a2632bca
AJ
560/**
561 * Write a 32 bits float to memory stored as big endian.
562 * @param p a pointer to the output memory
563 * @param x the input float
564 */
f1833600
GS
565static inline void write_fltbe(uint8_t *p, float x)
566{
567 union { uint32_t u; float f; } u;
568 u.f = x;
569 write_u32be(p, u.u);
570}
571#define WBFL(p, x) write_fltbe((uint8_t *)(p), (x))
a2632bca
AJ
572
573/**
574 * Write a 32 bits float to memory stored as little endian.
575 * @param p a pointer to the output memory
576 * @param x the input float
577 */
f1833600
GS
578static inline void write_fltle(uint8_t *p, float x)
579{
580 union { uint32_t u; float f; } u;
581 u.f = x;
582 write_u32le(p, u.u);
583}
584#define WLFL(p, x) write_fltle((uint8_t *)(p), float (x))
585
daa895cb
GS
586/**
587 * Write a 64 bits float to memory stored as little endian.
588 * @param p a pointer to the output memory
589 * @param x the input floating point value
590 */
591static inline void write_dblle(uint8_t *p, double x)
592{
593 union { uint64_t u; double f; } u;
594 u.f = x;
595 write_u64le(p, u.u);
596}
597#define WLDB(p, x) write_dblle((uint8_t *)(p), float (x))
598
f1833600
GS
599/* Endianess conversion helpers with read/write position increment. */
600
601/**
602 * Read unsigned 8bit integer from raw memory, increment read position.
603 * @param[in, out] p Pointer into byte stream.
604 * @return Retrieved integer value, unsigned.
605 */
606static inline uint8_t read_u8_inc(const uint8_t **p)
607{
608 uint8_t v;
609
610 if (!p || !*p)
611 return 0;
612 v = read_u8(*p);
613 *p += sizeof(v);
614
615 return v;
616}
617
e721b1bf
GS
618/**
619 * Read unsigned 8bit integer, check length, increment read position.
620 * @param[in, out] p Pointer into byte stream.
621 * @param[in, out] l Remaining input payload length.
622 * @return Retrieved integer value, unsigned.
623 */
624static inline uint8_t read_u8_inc_len(const uint8_t **p, size_t *l)
625{
626 uint8_t v;
627
628 if (!p || !*p)
629 return 0;
630 if (l && *l < sizeof(v)) {
631 *l = 0;
632 return 0;
633 }
634 v = read_u8(*p);
635 *p += sizeof(v);
636 if (l)
637 *l -= sizeof(v);
638
639 return v;
640}
641
e4bcc63d
GS
642/**
643 * Read signed 8bit integer from raw memory, increment read position.
644 * @param[in, out] p Pointer into byte stream.
645 * @return Retrieved integer value, signed.
646 */
647static inline int8_t read_i8_inc(const uint8_t **p)
648{
649 int8_t v;
650
651 if (!p || !*p)
652 return 0;
653 v = read_i8(*p);
654 *p += sizeof(v);
655
656 return v;
657}
658
f1833600
GS
659/**
660 * Read unsigned 16bit integer from raw memory (big endian format), increment read position.
661 * @param[in, out] p Pointer into byte stream.
662 * @return Retrieved integer value, unsigned.
663 */
664static inline uint16_t read_u16be_inc(const uint8_t **p)
665{
666 uint16_t v;
667
668 if (!p || !*p)
669 return 0;
670 v = read_u16be(*p);
671 *p += sizeof(v);
672
673 return v;
674}
675
676/**
677 * Read unsigned 16bit integer from raw memory (little endian format), increment read position.
678 * @param[in, out] p Pointer into byte stream.
679 * @return Retrieved integer value, unsigned.
680 */
681static inline uint16_t read_u16le_inc(const uint8_t **p)
682{
683 uint16_t v;
684
685 if (!p || !*p)
686 return 0;
687 v = read_u16le(*p);
688 *p += sizeof(v);
689
690 return v;
691}
692
e721b1bf
GS
693/**
694 * Read unsigned 16bit integer (LE format), check length, increment position.
695 * @param[in, out] p Pointer into byte stream.
696 * @param[in, out] l Remaining input payload length.
697 * @return Retrieved integer value, unsigned.
698 */
699static inline uint16_t read_u16le_inc_len(const uint8_t **p, size_t *l)
700{
701 uint16_t v;
702
703 if (!p || !*p)
704 return 0;
705 if (l && *l < sizeof(v)) {
706 *l = 0;
707 return 0;
708 }
709 v = read_u16le(*p);
710 *p += sizeof(v);
711 if (l)
712 *l -= sizeof(v);
713
714 return v;
715}
716
f1833600 717/**
e4bcc63d 718 * Read signed 16bit integer from raw memory (big endian format), increment read position.
f1833600 719 * @param[in, out] p Pointer into byte stream.
e4bcc63d 720 * @return Retrieved integer value, signed.
f1833600 721 */
e4bcc63d 722static inline int16_t read_i16be_inc(const uint8_t **p)
f1833600 723{
e4bcc63d 724 int16_t v;
f1833600
GS
725
726 if (!p || !*p)
727 return 0;
e4bcc63d
GS
728 v = read_i16be(*p);
729 *p += sizeof(v);
730
731 return v;
732}
733
734/**
735 * Read signed 16bit integer from raw memory (little endian format), increment read position.
736 * @param[in, out] p Pointer into byte stream.
737 * @return Retrieved integer value, signed.
738 */
739static inline int16_t read_i16le_inc(const uint8_t **p)
740{
741 int16_t v;
742
743 if (!p || !*p)
744 return 0;
745 v = read_i16le(*p);
f1833600
GS
746 *p += sizeof(v);
747
748 return v;
749}
750
080b6bcf
GS
751/**
752 * Read unsigned 24bit integer from raw memory (little endian format), increment read position.
753 * @param[in, out] p Pointer into byte stream.
754 * @return Retrieved integer value, unsigned.
755 */
756static inline uint32_t read_u24le_inc(const uint8_t **p)
757{
758 uint32_t v;
759
760 if (!p || !*p)
761 return 0;
762 v = read_u24le(*p);
763 *p += 3 * sizeof(uint8_t);
764
765 return v;
766}
767
e4bcc63d
GS
768/**
769 * Read unsigned 32bit integer from raw memory (big endian format), increment read position.
770 * @param[in, out] p Pointer into byte stream.
771 * @return Retrieved integer value, unsigned.
772 */
773static inline uint32_t read_u32be_inc(const uint8_t **p)
774{
775 uint32_t v;
776
777 if (!p || !*p)
778 return 0;
779 v = read_u32be(*p);
780 *p += sizeof(v);
781
782 return v;
783}
784
f1833600
GS
785/**
786 * Read unsigned 32bit integer from raw memory (little endian format), increment read position.
787 * @param[in, out] p Pointer into byte stream.
788 * @return Retrieved integer value, unsigned.
789 */
790static inline uint32_t read_u32le_inc(const uint8_t **p)
791{
792 uint32_t v;
793
794 if (!p || !*p)
795 return 0;
796 v = read_u32le(*p);
797 *p += sizeof(v);
798
799 return v;
800}
801
e4bcc63d
GS
802/**
803 * Read signed 32bit integer from raw memory (big endian format), increment read position.
804 * @param[in, out] p Pointer into byte stream.
805 * @return Retrieved integer value, signed.
806 */
807static inline int32_t read_i32be_inc(const uint8_t **p)
808{
809 int32_t v;
810
811 if (!p || !*p)
812 return 0;
813 v = read_i32be(*p);
814 *p += sizeof(v);
815
816 return v;
817}
818
819/**
820 * Read signed 32bit integer from raw memory (little endian format), increment read position.
821 * @param[in, out] p Pointer into byte stream.
822 * @return Retrieved integer value, signed.
823 */
824static inline int32_t read_i32le_inc(const uint8_t **p)
825{
826 int32_t v;
827
828 if (!p || !*p)
829 return 0;
830 v = read_i32le(*p);
831 *p += sizeof(v);
832
833 return v;
834}
835
f1833600
GS
836/**
837 * Read unsigned 64bit integer from raw memory (big endian format), increment read position.
838 * @param[in, out] p Pointer into byte stream.
839 * @return Retrieved integer value, unsigned.
840 */
841static inline uint64_t read_u64be_inc(const uint8_t **p)
842{
843 uint64_t v;
844
845 if (!p || !*p)
846 return 0;
847 v = read_u64be(*p);
848 *p += sizeof(v);
849
850 return v;
851}
852
853/**
854 * Read unsigned 64bit integer from raw memory (little endian format), increment read position.
855 * @param[in, out] p Pointer into byte stream.
856 * @return Retrieved integer value, unsigned.
857 */
858static inline uint64_t read_u64le_inc(const uint8_t **p)
859{
860 uint64_t v;
861
862 if (!p || !*p)
863 return 0;
864 v = read_u64le(*p);
865 *p += sizeof(v);
866
867 return v;
868}
869
e4bcc63d
GS
870/**
871 * Read 32bit float from raw memory (big endian format), increment read position.
872 * @param[in, out] p Pointer into byte stream.
873 * @return Retrieved float value.
874 */
875static inline float read_fltbe_inc(const uint8_t **p)
876{
877 float v;
878
879 if (!p || !*p)
880 return 0;
881 v = read_fltbe(*p);
882 *p += sizeof(v);
883
884 return v;
885}
886
daa895cb
GS
887/**
888 * Read 32bit float from raw memory (little endian format), increment read position.
889 * @param[in, out] p Pointer into byte stream.
890 * @return Retrieved float value.
891 */
892static inline float read_fltle_inc(const uint8_t **p)
893{
894 float v;
895
896 if (!p || !*p)
897 return 0;
898 v = read_fltle(*p);
899 *p += sizeof(v);
900
901 return v;
902}
903
e4bcc63d
GS
904/**
905 * Read 64bit float from raw memory (big endian format), increment read position.
906 * @param[in, out] p Pointer into byte stream.
907 * @return Retrieved float value.
908 */
909static inline double read_dblbe_inc(const uint8_t **p)
910{
911 double v;
912
913 if (!p || !*p)
914 return 0;
915 v = read_dblbe(*p);
916 *p += sizeof(v);
917
918 return v;
919}
920
daa895cb
GS
921/**
922 * Read 64bit float from raw memory (little endian format), increment read position.
923 * @param[in, out] p Pointer into byte stream.
924 * @return Retrieved float value.
925 */
926static inline double read_dblle_inc(const uint8_t **p)
927{
928 double v;
929
930 if (!p || !*p)
931 return 0;
932 v = read_dblle(*p);
933 *p += sizeof(v);
934
935 return v;
936}
937
f1833600
GS
938/**
939 * Write unsigned 8bit integer to raw memory, increment write position.
940 * @param[in, out] p Pointer into byte stream.
941 * @param[in] x Value to write.
942 */
943static inline void write_u8_inc(uint8_t **p, uint8_t x)
944{
945 if (!p || !*p)
946 return;
947 write_u8(*p, x);
948 *p += sizeof(x);
949}
950
951/**
952 * Write unsigned 16bit big endian integer to raw memory, increment write position.
953 * @param[in, out] p Pointer into byte stream.
954 * @param[in] x Value to write.
955 */
956static inline void write_u16be_inc(uint8_t **p, uint16_t x)
957{
958 if (!p || !*p)
959 return;
960 write_u16be(*p, x);
961 *p += sizeof(x);
962}
963
964/**
965 * Write unsigned 16bit little endian integer to raw memory, increment write position.
966 * @param[in, out] p Pointer into byte stream.
967 * @param[in] x Value to write.
968 */
969static inline void write_u16le_inc(uint8_t **p, uint16_t x)
970{
971 if (!p || !*p)
972 return;
973 write_u16le(*p, x);
974 *p += sizeof(x);
975}
976
15526343
GS
977/**
978 * Write unsigned 24bit liggle endian integer to raw memory, increment write position.
979 * @param[in, out] p Pointer into byte stream.
980 * @param[in] x Value to write.
981 */
982static inline void write_u24le_inc(uint8_t **p, uint32_t x)
983{
984 if (!p || !*p)
985 return;
986 write_u24le(*p, x);
987 *p += 3 * sizeof(uint8_t);
988}
989
f1833600
GS
990/**
991 * Write unsigned 32bit big endian integer to raw memory, increment write position.
992 * @param[in, out] p Pointer into byte stream.
993 * @param[in] x Value to write.
994 */
995static inline void write_u32be_inc(uint8_t **p, uint32_t x)
996{
997 if (!p || !*p)
998 return;
999 write_u32be(*p, x);
1000 *p += sizeof(x);
1001}
1002
1003/**
1004 * Write unsigned 32bit little endian integer to raw memory, increment write position.
1005 * @param[in, out] p Pointer into byte stream.
1006 * @param[in] x Value to write.
1007 */
1008static inline void write_u32le_inc(uint8_t **p, uint32_t x)
1009{
1010 if (!p || !*p)
1011 return;
1012 write_u32le(*p, x);
1013 *p += sizeof(x);
1014}
a2632bca 1015
15526343
GS
1016/**
1017 * Write unsigned 40bit little endian integer to raw memory, increment write position.
1018 * @param[in, out] p Pointer into byte stream.
1019 * @param[in] x Value to write.
1020 */
1021static inline void write_u40le_inc(uint8_t **p, uint64_t x)
1022{
1023 if (!p || !*p)
1024 return;
1025 write_u40le(*p, x);
1026 *p += 5 * sizeof(uint8_t);
1027}
1028
797c8d90
GS
1029/**
1030 * Write unsigned 48bit little endian integer to raw memory, increment write position.
1031 * @param[in, out] p Pointer into byte stream.
1032 * @param[in] x Value to write.
1033 */
1034static inline void write_u48le_inc(uint8_t **p, uint64_t x)
1035{
1036 if (!p || !*p)
1037 return;
1038 write_u48le(*p, x);
1039 *p += 48 / 8 * sizeof(uint8_t);
1040}
1041
daa895cb
GS
1042/**
1043 * Write unsigned 64bit little endian integer to raw memory, increment write position.
1044 * @param[in, out] p Pointer into byte stream.
1045 * @param[in] x Value to write.
1046 */
1047static inline void write_u64le_inc(uint8_t **p, uint64_t x)
1048{
1049 if (!p || !*p)
1050 return;
1051 write_u64le(*p, x);
1052 *p += sizeof(x);
1053}
1054
1055/**
1056 * Write single precision little endian float to raw memory, increment write position.
1057 * @param[in, out] p Pointer into byte stream.
1058 * @param[in] x Value to write.
1059 */
1060static inline void write_fltle_inc(uint8_t **p, float x)
1061{
1062 if (!p || !*p)
1063 return;
1064 write_fltle(*p, x);
1065 *p += sizeof(x);
1066}
1067
1068/**
1069 * Write double precision little endian float to raw memory, increment write position.
1070 * @param[in, out] p Pointer into byte stream.
1071 * @param[in] x Value to write.
1072 */
1073static inline void write_dblle_inc(uint8_t **p, double x)
1074{
1075 if (!p || !*p)
1076 return;
1077 write_dblle(*p, x);
1078 *p += sizeof(x);
1079}
1080
6bf4273e
UH
1081/* Portability fixes for FreeBSD. */
1082#ifdef __FreeBSD__
1083#define LIBUSB_CLASS_APPLICATION 0xfe
15eea61a 1084#define libusb_has_capability(x) 0
6bf4273e
UH
1085#define libusb_handle_events_timeout_completed(ctx, tv, c) \
1086 libusb_handle_events_timeout(ctx, tv)
1087#endif
1088
e1a712ca
GS
1089/*
1090 * Convenience for FTDI library version dependency.
1091 * - Version 1.5 introduced ftdi_tciflush(), ftdi_tcoflush(), and
1092 * ftdi_tcioflush() all within the same commit, and deprecated
1093 * ftdi_usb_purge_buffers() which suffered from inverse semantics.
1094 * The API is drop-in compatible (arguments count and data types are
1095 * identical). The libsigrok source code always flushes RX and TX at
1096 * the same time, never individually.
1097 */
1098#if defined HAVE_FTDI_TCIOFLUSH && HAVE_FTDI_TCIOFLUSH
1099# define PURGE_FTDI_BOTH ftdi_tcioflush
1100#else
1101# define PURGE_FTDI_BOTH ftdi_usb_purge_buffers
1102#endif
1103
1685c276
BV
1104/* Static definitions of structs ending with an all-zero entry are a
1105 * problem when compiling with -Wmissing-field-initializers: GCC
1106 * suppresses the warning only with { 0 }, clang wants { } */
1107#ifdef __clang__
1108#define ALL_ZERO { }
1109#else
1110#define ALL_ZERO { 0 }
1111#endif
1112
dd5c48a6
LPC
1113#ifdef __APPLE__
1114#define SR_DRIVER_LIST_SECTION "__DATA,__sr_driver_list"
1115#else
02a8c07d 1116#define SR_DRIVER_LIST_SECTION "__sr_driver_list"
dd5c48a6
LPC
1117#endif
1118
3decd3b1
GS
1119#if !defined SR_DRIVER_LIST_NOREORDER && defined __has_attribute
1120#if __has_attribute(no_reorder)
1121#define SR_DRIVER_LIST_NOREORDER __attribute__((no_reorder))
1122#endif
1123#endif
1124#if !defined SR_DRIVER_LIST_NOREORDER
1125#define SR_DRIVER_LIST_NOREORDER /* EMPTY */
1126#endif
1127
dd5c48a6
LPC
1128/**
1129 * Register a list of hardware drivers.
1130 *
1131 * This macro can be used to register multiple hardware drivers to the library.
1132 * This is useful when a driver supports multiple similar but slightly
1133 * different devices that require different sr_dev_driver struct definitions.
1134 *
1135 * For registering only a single driver see SR_REGISTER_DEV_DRIVER().
1136 *
1137 * Example:
1138 * @code{c}
1139 * #define MY_DRIVER(_name) \
1140 * &(struct sr_dev_driver){ \
1141 * .name = _name, \
1142 * ...
1143 * };
1144 *
1145 * SR_REGISTER_DEV_DRIVER_LIST(my_driver_infos,
1146 * MY_DRIVER("driver 1"),
1147 * MY_DRIVER("driver 2"),
1148 * ...
1149 * );
1150 * @endcode
1151 *
1152 * @param name Name to use for the driver list identifier.
1153 * @param ... Comma separated list of pointers to sr_dev_driver structs.
1154 */
1155#define SR_REGISTER_DEV_DRIVER_LIST(name, ...) \
1156 static const struct sr_dev_driver *name[] \
3decd3b1 1157 SR_DRIVER_LIST_NOREORDER \
dd5c48a6
LPC
1158 __attribute__((section (SR_DRIVER_LIST_SECTION), used, \
1159 aligned(sizeof(struct sr_dev_driver *)))) \
1160 = { \
1161 __VA_ARGS__ \
1162 };
1163
1164/**
1165 * Register a hardware driver.
1166 *
1167 * This macro is used to register a hardware driver with the library. It has
1168 * to be used in order to make the driver accessible to applications using the
1169 * library.
1170 *
1171 * The macro invocation should be placed directly under the struct
1172 * sr_dev_driver definition.
1173 *
1174 * Example:
1175 * @code{c}
1176 * static struct sr_dev_driver driver_info = {
1177 * .name = "driver",
1178 * ....
1179 * };
1180 * SR_REGISTER_DEV_DRIVER(driver_info);
1181 * @endcode
1182 *
1183 * @param name Identifier name of sr_dev_driver struct to register.
1184 */
1185#define SR_REGISTER_DEV_DRIVER(name) \
1186 SR_REGISTER_DEV_DRIVER_LIST(name##_list, &name);
1187
ced48274 1188SR_API void sr_drivers_init(struct sr_context *context);
5d8b3913 1189
b8072700 1190struct sr_context {
032da34b 1191 struct sr_dev_driver **driver_list;
785b9ff2
PS
1192#ifdef HAVE_LIBUSB_1_0
1193 libusb_context *libusb_ctx;
1194#endif
bee24666
DE
1195 sr_resource_open_callback resource_open_cb;
1196 sr_resource_close_callback resource_close_cb;
1197 sr_resource_read_callback resource_read_cb;
1198 void *resource_cb_data;
b8072700
PS
1199};
1200
20e88821
BV
1201/** Input module metadata keys. */
1202enum sr_input_meta_keys {
1203 /** The input filename, if there is one. */
1204 SR_INPUT_META_FILENAME = 0x01,
1205 /** The input file's size in bytes. */
1206 SR_INPUT_META_FILESIZE = 0x02,
1207 /** The first 128 bytes of the file, provided as a GString. */
1208 SR_INPUT_META_HEADER = 0x04,
20e88821
BV
1209
1210 /** The module cannot identify a file without this metadata. */
1211 SR_INPUT_META_REQUIRED = 0x80,
1212};
1213
d514d35d
BV
1214/** Input (file) module struct. */
1215struct sr_input {
1216 /**
1217 * A pointer to this input module's 'struct sr_input_module'.
d514d35d 1218 */
17bfaca6
BV
1219 const struct sr_input_module *module;
1220 GString *buf;
d514d35d 1221 struct sr_dev_inst *sdi;
d0181813 1222 gboolean sdi_ready;
17bfaca6 1223 void *priv;
d514d35d
BV
1224};
1225
1226/** Input (file) module driver. */
1227struct sr_input_module {
17bfaca6 1228 /**
d65fcbcd 1229 * A unique ID for this input module, suitable for use in command-line
17bfaca6
BV
1230 * clients, [a-z0-9-]. Must not be NULL.
1231 */
1232 const char *id;
d514d35d
BV
1233
1234 /**
d65fcbcd 1235 * A unique name for this input module, suitable for use in GUI
17bfaca6 1236 * clients, can contain UTF-8. Must not be NULL.
d514d35d 1237 */
17bfaca6 1238 const char *name;
d514d35d
BV
1239
1240 /**
d65fcbcd 1241 * A short description of the input module. Must not be NULL.
d514d35d 1242 *
d65fcbcd 1243 * This can be displayed by frontends, e.g. when selecting the input
17bfaca6
BV
1244 * module for saving a file.
1245 */
1246 const char *desc;
1247
c7bc82ff
JH
1248 /**
1249 * A NULL terminated array of strings containing a list of file name
1250 * extensions typical for the input file format, or NULL if there is
1251 * no typical extension for this file format.
1252 */
1253 const char *const *exts;
1254
17bfaca6
BV
1255 /**
1256 * Zero-terminated list of metadata items the module needs to be able
1257 * to identify an input stream. Can be all-zero, if the module cannot
1258 * identify streams at all, i.e. has to be forced into use.
1259 *
1260 * Each item is one of:
1261 * SR_INPUT_META_FILENAME
1262 * SR_INPUT_META_FILESIZE
1263 * SR_INPUT_META_HEADER
17bfaca6
BV
1264 *
1265 * If the high bit (SR_INPUT META_REQUIRED) is set, the module cannot
1266 * identify a stream without the given metadata.
1267 */
1268 const uint8_t metadata[8];
1269
1270 /**
1271 * Returns a NULL-terminated list of options this module can take.
1272 * Can be NULL, if the module has no options.
1273 */
2c240774 1274 const struct sr_option *(*options) (void);
17bfaca6
BV
1275
1276 /**
1277 * Check if this input module can load and parse the specified stream.
1278 *
1279 * @param[in] metadata Metadata the module can use to identify the stream.
54ee427d
GS
1280 * @param[out] confidence "Strength" of the detection.
1281 * Specialized handlers can take precedence over generic/basic support.
d514d35d 1282 *
4f979115 1283 * @retval SR_OK This module knows the format.
753793ef 1284 * @retval SR_ERR_NA There wasn't enough data for this module to
4f979115 1285 * positively identify the format.
d9251a2c
UH
1286 * @retval SR_ERR_DATA This module knows the format, but cannot handle
1287 * it. This means the stream is either corrupt, or indicates a
1288 * feature that the module does not support.
4f979115 1289 * @retval SR_ERR This module does not know the format.
54ee427d
GS
1290 *
1291 * Lower numeric values of 'confidence' mean that the input module
1292 * stronger believes in its capability to handle this specific format.
1293 * This way, multiple input modules can claim support for a format,
1294 * and the application can pick the best match, or try fallbacks
1295 * in case of errors. This approach also copes with formats that
1296 * are unreliable to detect in the absence of magic signatures.
d514d35d 1297 */
54ee427d 1298 int (*format_match) (GHashTable *metadata, unsigned int *confidence);
d514d35d
BV
1299
1300 /**
1301 * Initialize the input module.
1302 *
d514d35d
BV
1303 * @retval SR_OK Success
1304 * @retval other Negative error code.
1305 */
17bfaca6 1306 int (*init) (struct sr_input *in, GHashTable *options);
d514d35d
BV
1307
1308 /**
753793ef 1309 * Send data to the specified input instance.
d514d35d 1310 *
753793ef
BV
1311 * When an input module instance is created with sr_input_new(), this
1312 * function is used to feed data to the instance.
d514d35d 1313 *
753793ef
BV
1314 * As enough data gets fed into this function to completely populate
1315 * the device instance associated with this input instance, this is
1316 * guaranteed to return the moment it's ready. This gives the caller
1317 * the chance to examine the device instance, attach session callbacks
1318 * and so on.
17bfaca6
BV
1319 *
1320 * @retval SR_OK Success
1321 * @retval other Negative error code.
1322 */
d0181813 1323 int (*receive) (struct sr_input *in, GString *buf);
17bfaca6 1324
753793ef
BV
1325 /**
1326 * Signal the input module no more data will come.
1327 *
1328 * This will cause the module to process any data it may have buffered.
1329 * The SR_DF_END packet will also typically be sent at this time.
1330 */
7066fd46
BV
1331 int (*end) (struct sr_input *in);
1332
d9251a2c
UH
1333 /**
1334 * Reset the input module's input handling structures.
1335 *
1336 * Causes the input module to reset its internal state so that we can
1337 * re-send the input data from the beginning without having to
1338 * re-create the entire input module.
1339 *
1340 * @retval SR_OK Success.
1341 * @retval other Negative error code.
1342 */
b6b4f03e
SA
1343 int (*reset) (struct sr_input *in);
1344
17bfaca6
BV
1345 /**
1346 * This function is called after the caller is finished using
1347 * the input module, and can be used to free any internal
1348 * resources the module may keep.
d514d35d 1349 *
753793ef
BV
1350 * This function is optional.
1351 *
d514d35d
BV
1352 * @retval SR_OK Success
1353 * @retval other Negative error code.
1354 */
d5cc282f 1355 void (*cleanup) (struct sr_input *in);
d514d35d
BV
1356};
1357
a755b0e1
BV
1358/** Output module instance. */
1359struct sr_output {
d9251a2c 1360 /** A pointer to this output's module. */
a755b0e1
BV
1361 const struct sr_output_module *module;
1362
1363 /**
1364 * The device for which this output module is creating output. This
1365 * can be used by the module to find out channel names and numbers.
1366 */
1367 const struct sr_dev_inst *sdi;
1368
81b3ce37
SA
1369 /**
1370 * The name of the file that the data should be written to.
1371 */
1372 const char *filename;
1373
a755b0e1
BV
1374 /**
1375 * A generic pointer which can be used by the module to keep internal
1376 * state between calls into its callback functions.
1377 *
1378 * For example, the module might store a pointer to a chunk of output
1379 * there, and only flush it when it reaches a certain size.
1380 */
d686c5ec 1381 void *priv;
a755b0e1
BV
1382};
1383
1384/** Output module driver. */
1385struct sr_output_module {
1386 /**
1387 * A unique ID for this output module, suitable for use in command-line
1388 * clients, [a-z0-9-]. Must not be NULL.
1389 */
2c240774 1390 const char *id;
a755b0e1
BV
1391
1392 /**
1393 * A unique name for this output module, suitable for use in GUI
1394 * clients, can contain UTF-8. Must not be NULL.
1395 */
1396 const char *name;
1397
1398 /**
1399 * A short description of the output module. Must not be NULL.
1400 *
1401 * This can be displayed by frontends, e.g. when selecting the output
1402 * module for saving a file.
1403 */
2c240774 1404 const char *desc;
a755b0e1 1405
8a174d23
JH
1406 /**
1407 * A NULL terminated array of strings containing a list of file name
1408 * extensions typical for the input file format, or NULL if there is
1409 * no typical extension for this file format.
1410 */
1411 const char *const *exts;
1412
3cd4b381
SA
1413 /**
1414 * Bitfield containing flags that describe certain properties
1415 * this output module may or may not have.
1416 * @see sr_output_flags
1417 */
1418 const uint64_t flags;
1419
a755b0e1
BV
1420 /**
1421 * Returns a NULL-terminated list of options this module can take.
1422 * Can be NULL, if the module has no options.
a755b0e1 1423 */
af7d656d 1424 const struct sr_option *(*options) (void);
a755b0e1
BV
1425
1426 /**
1427 * This function is called once, at the beginning of an output stream.
1428 *
1429 * The device struct will be available in the output struct passed in,
1430 * as well as the param field -- which may be NULL or an empty string,
1431 * if no parameter was passed.
1432 *
1433 * The module can use this to initialize itself, create a struct for
1434 * keeping state and storing it in the <code>internal</code> field.
1435 *
1436 * @param o Pointer to the respective 'struct sr_output'.
1437 *
1438 * @retval SR_OK Success
1439 * @retval other Negative error code.
1440 */
1441 int (*init) (struct sr_output *o, GHashTable *options);
1442
1443 /**
f3f19d11 1444 * This function is passed a copy of every packet in the data feed.
a755b0e1
BV
1445 * Any output generated by the output module in response to the
1446 * packet should be returned in a newly allocated GString
1447 * <code>out</code>, which will be freed by the caller.
1448 *
1449 * Packets not of interest to the output module can just be ignored,
1450 * and the <code>out</code> parameter set to NULL.
1451 *
1452 * @param o Pointer to the respective 'struct sr_output'.
1453 * @param sdi The device instance that generated the packet.
1454 * @param packet The complete packet.
1455 * @param out A pointer where a GString * should be stored if
1456 * the module generates output, or NULL if not.
1457 *
1458 * @retval SR_OK Success
1459 * @retval other Negative error code.
1460 */
1461 int (*receive) (const struct sr_output *o,
1462 const struct sr_datafeed_packet *packet, GString **out);
1463
1464 /**
1465 * This function is called after the caller is finished using
1466 * the output module, and can be used to free any internal
1467 * resources the module may keep.
1468 *
1469 * @retval SR_OK Success
1470 * @retval other Negative error code.
1471 */
1472 int (*cleanup) (struct sr_output *o);
1473};
1474
790320f6
UH
1475/** Transform module instance. */
1476struct sr_transform {
d9251a2c 1477 /** A pointer to this transform's module. */
790320f6
UH
1478 const struct sr_transform_module *module;
1479
1480 /**
1481 * The device for which this transform module is used. This
1482 * can be used by the module to find out channel names and numbers.
1483 */
1484 const struct sr_dev_inst *sdi;
1485
1486 /**
1487 * A generic pointer which can be used by the module to keep internal
1488 * state between calls into its callback functions.
1489 */
1490 void *priv;
1491};
1492
1493struct sr_transform_module {
1494 /**
1495 * A unique ID for this transform module, suitable for use in
1496 * command-line clients, [a-z0-9-]. Must not be NULL.
1497 */
2c240774 1498 const char *id;
790320f6
UH
1499
1500 /**
1501 * A unique name for this transform module, suitable for use in GUI
1502 * clients, can contain UTF-8. Must not be NULL.
1503 */
1504 const char *name;
1505
1506 /**
1507 * A short description of the transform module. Must not be NULL.
1508 *
1509 * This can be displayed by frontends, e.g. when selecting
1510 * which transform module(s) to add.
1511 */
2c240774 1512 const char *desc;
790320f6
UH
1513
1514 /**
1515 * Returns a NULL-terminated list of options this transform module
1516 * can take. Can be NULL, if the transform module has no options.
1517 */
1518 const struct sr_option *(*options) (void);
1519
1520 /**
1521 * This function is called once, at the beginning of a stream.
1522 *
1523 * @param t Pointer to the respective 'struct sr_transform'.
1524 * @param options Hash table of options for this transform module.
1525 * Can be NULL if no options are to be used.
1526 *
1527 * @retval SR_OK Success
1528 * @retval other Negative error code.
1529 */
1530 int (*init) (struct sr_transform *t, GHashTable *options);
1531
1532 /**
1533 * This function is passed a pointer to every packet in the data feed.
1534 *
1535 * It can either return (in packet_out) a pointer to another packet
1536 * (possibly the exact same packet it got as input), or NULL.
1537 *
1538 * @param t Pointer to the respective 'struct sr_transform'.
1539 * @param packet_in Pointer to a datafeed packet.
1540 * @param packet_out Pointer to the resulting datafeed packet after
1541 * this function was run. If NULL, the transform
1542 * module intentionally didn't output a new packet.
1543 *
1544 * @retval SR_OK Success
1545 * @retval other Negative error code.
1546 */
1547 int (*receive) (const struct sr_transform *t,
1548 struct sr_datafeed_packet *packet_in,
1549 struct sr_datafeed_packet **packet_out);
1550
1551 /**
1552 * This function is called after the caller is finished using
1553 * the transform module, and can be used to free any internal
1554 * resources the module may keep.
1555 *
1556 * @retval SR_OK Success
1557 * @retval other Negative error code.
1558 */
1559 int (*cleanup) (struct sr_transform *t);
1560};
1561
69890f73 1562#ifdef HAVE_LIBUSB_1_0
04cb9157 1563/** USB device instance */
d68e2d1a 1564struct sr_usb_dev_inst {
98582bf5
BV
1565 /** USB bus */
1566 uint8_t bus;
1567 /** Device address on USB bus */
1568 uint8_t address;
1569 /** libusb device handle */
1570 struct libusb_device_handle *devhdl;
69890f73
UH
1571};
1572#endif
1573
1ac8c218 1574struct sr_serial_dev_inst;
1df81f4b 1575#ifdef HAVE_SERIAL_COMM
a7b8692e 1576struct ser_lib_functions;
edec0436 1577struct ser_hid_chip_functions;
b79c3422 1578struct sr_bt_desc;
d4787248
GS
1579typedef void (*serial_rx_chunk_callback)(struct sr_serial_dev_inst *serial,
1580 void *cb_data, const void *buf, size_t count);
d68e2d1a 1581struct sr_serial_dev_inst {
98582bf5
BV
1582 /** Port name, e.g. '/dev/tty42'. */
1583 char *port;
1584 /** Comm params for serial_set_paramstr(). */
1585 char *serialcomm;
a7b8692e 1586 struct ser_lib_functions *lib_funcs;
639c6f61
GS
1587 struct {
1588 int bit_rate;
1589 int data_bits;
1590 int parity_bits;
1591 int stop_bits;
1592 } comm_params;
ad5aa993 1593 GString *rcv_buffer;
d4787248
GS
1594 serial_rx_chunk_callback rx_chunk_cb_func;
1595 void *rx_chunk_cb_data;
a7b8692e 1596#ifdef HAVE_LIBSERIALPORT
98582bf5 1597 /** libserialport port handle */
271392d9 1598 struct sp_port *sp_data;
a7b8692e 1599#endif
4417074c 1600#ifdef HAVE_LIBHIDAPI
edec0436
GS
1601 enum ser_hid_chip_t {
1602 SER_HID_CHIP_UNKNOWN, /**!< place holder */
a10284cd 1603 SER_HID_CHIP_BTC_BU86X, /**!< Brymen BU86x */
616bc3a1 1604 SER_HID_CHIP_SIL_CP2110, /**!< SiLabs CP2110 */
0cdb72c8 1605 SER_HID_CHIP_VICTOR_DMM, /**!< Victor 70/86 DMM cable */
828eeea2 1606 SER_HID_CHIP_WCH_CH9325, /**!< WCH CH9325 */
edec0436
GS
1607 SER_HID_CHIP_LAST, /**!< sentinel */
1608 } hid_chip;
1609 struct ser_hid_chip_functions *hid_chip_funcs;
1610 char *usb_path;
1611 char *usb_serno;
1612 const char *hid_path;
4417074c 1613 hid_device *hid_dev;
edec0436 1614 GSList *hid_source_args;
4417074c 1615#endif
b79c3422
GS
1616#ifdef HAVE_BLUETOOTH
1617 enum ser_bt_conn_t {
1618 SER_BT_CONN_UNKNOWN, /**!< place holder */
1619 SER_BT_CONN_RFCOMM, /**!< BT classic, RFCOMM channel */
1620 SER_BT_CONN_BLE122, /**!< BLE, BLE122 module, indications */
1621 SER_BT_CONN_NRF51, /**!< BLE, Nordic nRF51, notifications */
1622 SER_BT_CONN_CC254x, /**!< BLE, TI CC254x, notifications */
d0a73799 1623 SER_BT_CONN_AC6328, /**!< BLE, JL AC6328B, notifications */
b79c3422
GS
1624 SER_BT_CONN_MAX, /**!< sentinel */
1625 } bt_conn_type;
1626 char *bt_addr_local;
1627 char *bt_addr_remote;
1628 size_t bt_rfcomm_channel;
1629 uint16_t bt_notify_handle_read;
1630 uint16_t bt_notify_handle_write;
1631 uint16_t bt_notify_handle_cccd;
1632 uint16_t bt_notify_value_cccd;
1633 struct sr_bt_desc *bt_desc;
1634 GSList *bt_source_args;
1635#endif
69890f73 1636};
c4f2dfd0 1637#endif
69890f73 1638
ae67644f
ML
1639struct sr_usbtmc_dev_inst {
1640 char *device;
1641 int fd;
1642};
1643
026c822d
UH
1644/* Private driver context. */
1645struct drv_context {
98582bf5
BV
1646 /** sigrok context */
1647 struct sr_context *sr_ctx;
026c822d
UH
1648 GSList *instances;
1649};
1650
48a486cd
BV
1651/*--- log.c -----------------------------------------------------------------*/
1652
00f0016c 1653#if defined(_WIN32) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4))
7419638d
DE
1654/*
1655 * On MinGW, we need to specify the gnu_printf format flavor or GCC
1656 * will assume non-standard Microsoft printf syntax.
1657 */
1658SR_PRIV int sr_log(int loglevel, const char *format, ...)
1659 __attribute__((__format__ (__gnu_printf__, 2, 3)));
1660#else
be92d5b4 1661SR_PRIV int sr_log(int loglevel, const char *format, ...) G_GNUC_PRINTF(2, 3);
7419638d 1662#endif
48a486cd 1663
3544f848 1664/* Message logging helpers with subsystem-specific prefix string. */
be92d5b4
DE
1665#define sr_spew(...) sr_log(SR_LOG_SPEW, LOG_PREFIX ": " __VA_ARGS__)
1666#define sr_dbg(...) sr_log(SR_LOG_DBG, LOG_PREFIX ": " __VA_ARGS__)
1667#define sr_info(...) sr_log(SR_LOG_INFO, LOG_PREFIX ": " __VA_ARGS__)
1668#define sr_warn(...) sr_log(SR_LOG_WARN, LOG_PREFIX ": " __VA_ARGS__)
1669#define sr_err(...) sr_log(SR_LOG_ERR, LOG_PREFIX ": " __VA_ARGS__)
3544f848 1670
48a486cd
BV
1671/*--- device.c --------------------------------------------------------------*/
1672
cffdc3e6
ML
1673/** Scan options supported by a driver. */
1674#define SR_CONF_SCAN_OPTIONS 0x7FFF0000
1675
1676/** Device options for a particular device. */
1677#define SR_CONF_DEVICE_OPTIONS 0x7FFF0001
1678
e318f01b
ML
1679/** Mask for separating config keys from capabilities. */
1680#define SR_CONF_MASK 0x1fffffff
1681
f3ca73ed 1682/** Values for the changes argument of sr_dev_driver.config_channel_set. */
2a854d71 1683enum {
fca75cbb 1684 /** The enabled state of the channel has been changed. */
3f239f08 1685 SR_CHANNEL_SET_ENABLED = 1 << 0,
2a854d71
DE
1686};
1687
5e23fcab
ML
1688SR_PRIV struct sr_channel *sr_channel_new(struct sr_dev_inst *sdi,
1689 int index, int type, gboolean enabled, const char *name);
fe71c7e4
GS
1690SR_PRIV void sr_channel_free(struct sr_channel *ch);
1691SR_PRIV void sr_channel_free_cb(void *p);
9c24d16a
BV
1692SR_PRIV struct sr_channel *sr_next_enabled_channel(const struct sr_dev_inst *sdi,
1693 struct sr_channel *cur_channel);
712f981d
GS
1694SR_PRIV gboolean sr_channels_differ(struct sr_channel *ch1, struct sr_channel *ch2);
1695SR_PRIV gboolean sr_channel_lists_differ(GSList *l1, GSList *l2);
48a486cd 1696
1e7468a8
GS
1697SR_PRIV struct sr_channel_group *sr_channel_group_new(struct sr_dev_inst *sdi,
1698 const char *name, void *priv);
1699SR_PRIV void sr_channel_group_free(struct sr_channel_group *cg);
1700SR_PRIV void sr_channel_group_free_cb(void *cg);
1701
96727ef0
UH
1702/** Device instance data */
1703struct sr_dev_inst {
1704 /** Device driver. */
1705 struct sr_dev_driver *driver;
1706 /** Device instance status. SR_ST_NOT_FOUND, etc. */
1707 int status;
1708 /** Device instance type. SR_INST_USB, etc. */
1709 int inst_type;
1710 /** Device vendor. */
1711 char *vendor;
1712 /** Device model. */
1713 char *model;
1714 /** Device version. */
1715 char *version;
1716 /** Serial number. */
1717 char *serial_num;
1718 /** Connection string to uniquely identify devices. */
1719 char *connection_id;
1720 /** List of channels. */
1721 GSList *channels;
1722 /** List of sr_channel_group structs */
1723 GSList *channel_groups;
1724 /** Device instance connection data (used?) */
1725 void *conn;
1726 /** Device instance private data (used?) */
1727 void *priv;
1728 /** Session to which this device is currently assigned. */
1729 struct sr_session *session;
1730};
1731
48a486cd 1732/* Generic device instances */
48a486cd 1733SR_PRIV void sr_dev_inst_free(struct sr_dev_inst *sdi);
48a486cd 1734
545f9786 1735#ifdef HAVE_LIBUSB_1_0
69890f73 1736/* USB-specific instances */
d68e2d1a 1737SR_PRIV struct sr_usb_dev_inst *sr_usb_dev_inst_new(uint8_t bus,
69890f73 1738 uint8_t address, struct libusb_device_handle *hdl);
d68e2d1a 1739SR_PRIV void sr_usb_dev_inst_free(struct sr_usb_dev_inst *usb);
460c1334 1740SR_PRIV void sr_usb_dev_inst_free_cb(gpointer p); /* Glib wrapper. */
69890f73
UH
1741#endif
1742
1df81f4b 1743#ifdef HAVE_SERIAL_COMM
1ac8c218
GS
1744#ifndef HAVE_LIBSERIALPORT
1745/*
1746 * Some identifiers which initially got provided by libserialport are
1747 * used internally within the libsigrok serial layer's implementation,
1748 * while libserialport no longer is the exclusive provider of serial
1749 * communication support. Declare the identifiers here so they remain
1750 * available across all build configurations.
1751 */
1752enum libsp_parity {
1753 SP_PARITY_NONE = 0,
1754 SP_PARITY_ODD = 1,
1755 SP_PARITY_EVEN = 2,
1756 SP_PARITY_MARK = 3,
1757 SP_PARITY_SPACE = 4,
1758};
1759
1760enum libsp_flowcontrol {
1761 SP_FLOWCONTROL_NONE = 0,
1762 SP_FLOWCONTROL_XONXOFF = 1,
1763 SP_FLOWCONTROL_RTSCTS = 2,
1764 SP_FLOWCONTROL_DTRDSR = 3,
1765};
1766#endif
1767
69890f73 1768/* Serial-specific instances */
299bdb24
BV
1769SR_PRIV struct sr_serial_dev_inst *sr_serial_dev_inst_new(const char *port,
1770 const char *serialcomm);
d68e2d1a 1771SR_PRIV void sr_serial_dev_inst_free(struct sr_serial_dev_inst *serial);
c4f2dfd0 1772#endif
69890f73 1773
ae67644f
ML
1774/* USBTMC-specific instances */
1775SR_PRIV struct sr_usbtmc_dev_inst *sr_usbtmc_dev_inst_new(const char *device);
1776SR_PRIV void sr_usbtmc_dev_inst_free(struct sr_usbtmc_dev_inst *usbtmc);
b08024a8 1777
c09f0b57 1778/*--- hwdriver.c ------------------------------------------------------------*/
996b0c72 1779
13fef1ed 1780SR_PRIV const GVariantType *sr_variant_type_get(int datatype);
584560f1 1781SR_PRIV int sr_variant_type_check(uint32_t key, GVariant *data);
032da34b 1782SR_PRIV void sr_hw_cleanup_all(const struct sr_context *ctx);
584560f1 1783SR_PRIV struct sr_config *sr_config_new(uint32_t key, GVariant *data);
722db131 1784SR_PRIV void sr_config_free(struct sr_config *src);
f670835f 1785SR_PRIV int sr_dev_acquisition_start(struct sr_dev_inst *sdi);
d2f7c417 1786SR_PRIV int sr_dev_acquisition_stop(struct sr_dev_inst *sdi);
996b0c72 1787
a1645fcd
BV
1788/*--- session.c -------------------------------------------------------------*/
1789
e2b23821 1790struct sr_session {
4ed5d21d
ML
1791 /** Context this session exists in. */
1792 struct sr_context *ctx;
c0e3ba4b 1793 /** List of struct sr_dev_inst pointers. */
e2b23821 1794 GSList *devs;
1de3cced
ML
1795 /** List of struct sr_dev_inst pointers owned by this session. */
1796 GSList *owned_devs;
e2b23821
UH
1797 /** List of struct datafeed_callback pointers. */
1798 GSList *datafeed_callbacks;
c0a1e532 1799 GSList *transforms;
7b5e6d29 1800 struct sr_trigger *trigger;
62d7945f 1801
5de0fc55
DE
1802 /** Callback to invoke on session stop. */
1803 sr_session_stopped_callback stopped_callback;
1804 /** User data to be passed to the session stop callback. */
1805 void *stopped_cb_data;
1806
2e5e3df4 1807 /** Mutex protecting the main context pointer. */
c2bf5506
DE
1808 GMutex main_mutex;
1809 /** Context of the session main loop. */
1810 GMainContext *main_context;
e2b23821 1811
c2bf5506
DE
1812 /** Registered event sources for this session. */
1813 GHashTable *event_sources;
1814 /** Session main loop. */
1815 GMainLoop *main_loop;
5de0fc55
DE
1816 /** ID of idle source for dispatching the session stop notification. */
1817 unsigned int stop_check_id;
2e5e3df4
DE
1818 /** Whether the session has been started. */
1819 gboolean running;
e2b23821
UH
1820};
1821
62d7945f 1822SR_PRIV int sr_session_source_add_internal(struct sr_session *session,
c2bf5506 1823 void *key, GSource *source);
92248e78 1824SR_PRIV int sr_session_source_remove_internal(struct sr_session *session,
c2bf5506
DE
1825 void *key);
1826SR_PRIV int sr_session_source_destroyed(struct sr_session *session,
1827 void *key, GSource *source);
cbc1413f
DE
1828SR_PRIV int sr_session_fd_source_add(struct sr_session *session,
1829 void *key, gintptr fd, int events, int timeout,
1830 sr_receive_data_callback cb, void *cb_data);
ee9953ef
DE
1831
1832SR_PRIV int sr_session_source_add(struct sr_session *session, int fd,
1833 int events, int timeout, sr_receive_data_callback cb, void *cb_data);
1834SR_PRIV int sr_session_source_add_pollfd(struct sr_session *session,
1835 GPollFD *pollfd, int timeout, sr_receive_data_callback cb,
1836 void *cb_data);
1837SR_PRIV int sr_session_source_add_channel(struct sr_session *session,
1838 GIOChannel *channel, int events, int timeout,
1839 sr_receive_data_callback cb, void *cb_data);
1840SR_PRIV int sr_session_source_remove(struct sr_session *session, int fd);
1841SR_PRIV int sr_session_source_remove_pollfd(struct sr_session *session,
1842 GPollFD *pollfd);
1843SR_PRIV int sr_session_source_remove_channel(struct sr_session *session,
1844 GIOChannel *channel);
1845
7d1a4a52
FS
1846SR_PRIV int sr_session_send_meta(const struct sr_dev_inst *sdi,
1847 uint32_t key, GVariant *var);
de4d3f99 1848SR_PRIV int sr_session_send(const struct sr_dev_inst *sdi,
ae5859ff 1849 const struct sr_datafeed_packet *packet);
f438e0c9 1850SR_PRIV int sr_sessionfile_check(const char *filename);
7c69b528
SA
1851SR_PRIV struct sr_dev_inst *sr_session_prepare_sdi(const char *filename,
1852 struct sr_session **session);
a1645fcd 1853
98654c99
DE
1854/*--- session_file.c --------------------------------------------------------*/
1855
a6dc3dac
DE
1856#if !HAVE_ZIP_DISCARD
1857/* Replace zip_discard() if not available. */
1858#define zip_discard(zip) sr_zip_discard(zip)
1859SR_PRIV void sr_zip_discard(struct zip *archive);
1860#endif
1861
98654c99
DE
1862SR_PRIV GKeyFile *sr_sessionfile_read_metadata(struct zip *archive,
1863 const struct zip_stat *entry);
1864
41caa319
AJ
1865/*--- analog.c --------------------------------------------------------------*/
1866
edb691fc 1867SR_PRIV int sr_analog_init(struct sr_datafeed_analog *analog,
41caa319
AJ
1868 struct sr_analog_encoding *encoding,
1869 struct sr_analog_meaning *meaning,
1870 struct sr_analog_spec *spec,
1871 int digits);
1872
063e7aef
UH
1873/*--- std.c -----------------------------------------------------------------*/
1874
144f6660
UH
1875typedef int (*dev_close_callback)(struct sr_dev_inst *sdi);
1876typedef void (*std_dev_clear_callback)(void *priv);
cd2f0fe2 1877
c45c32ce 1878SR_PRIV int std_init(struct sr_dev_driver *di, struct sr_context *sr_ctx);
700d6b64 1879SR_PRIV int std_cleanup(const struct sr_dev_driver *di);
4d67b9d9
UH
1880SR_PRIV int std_dummy_dev_open(struct sr_dev_inst *sdi);
1881SR_PRIV int std_dummy_dev_close(struct sr_dev_inst *sdi);
1882SR_PRIV int std_dummy_dev_acquisition_start(const struct sr_dev_inst *sdi);
1883SR_PRIV int std_dummy_dev_acquisition_stop(struct sr_dev_inst *sdi);
1df81f4b 1884#ifdef HAVE_SERIAL_COMM
23dc6661 1885SR_PRIV int std_serial_dev_open(struct sr_dev_inst *sdi);
1b38775b 1886SR_PRIV int std_serial_dev_acquisition_stop(struct sr_dev_inst *sdi);
c4f2dfd0 1887#endif
bee2b016
LPC
1888SR_PRIV int std_session_send_df_header(const struct sr_dev_inst *sdi);
1889SR_PRIV int std_session_send_df_end(const struct sr_dev_inst *sdi);
10cf8113 1890SR_PRIV int std_session_send_df_trigger(const struct sr_dev_inst *sdi);
7f7702b8
UH
1891SR_PRIV int std_session_send_df_frame_begin(const struct sr_dev_inst *sdi);
1892SR_PRIV int std_session_send_df_frame_end(const struct sr_dev_inst *sdi);
6e43c3d5 1893SR_PRIV int std_dev_clear_with_callback(const struct sr_dev_driver *driver,
144f6660 1894 std_dev_clear_callback clear_private);
f778bf02 1895SR_PRIV int std_dev_clear(const struct sr_dev_driver *driver);
c01bf34c 1896SR_PRIV GSList *std_dev_list(const struct sr_dev_driver *di);
043e899a 1897SR_PRIV int std_serial_dev_close(struct sr_dev_inst *sdi);
15a5bfe4 1898SR_PRIV GSList *std_scan_complete(struct sr_dev_driver *di, GSList *devices);
4afdfd46 1899
e66d1892
UH
1900SR_PRIV int std_opts_config_list(uint32_t key, GVariant **data,
1901 const struct sr_dev_inst *sdi, const struct sr_channel_group *cg,
1902 const uint32_t scanopts[], size_t scansize, const uint32_t drvopts[],
1903 size_t drvsize, const uint32_t devopts[], size_t devsize);
1904
23772462
UH
1905extern SR_PRIV const uint32_t NO_OPTS[1];
1906
e66d1892
UH
1907#define STD_CONFIG_LIST(key, data, sdi, cg, scanopts, drvopts, devopts) \
1908 std_opts_config_list(key, data, sdi, cg, ARRAY_AND_SIZE(scanopts), \
1909 ARRAY_AND_SIZE(drvopts), ARRAY_AND_SIZE(devopts))
1910
58ffcf97 1911SR_PRIV GVariant *std_gvar_tuple_array(const uint64_t a[][2], unsigned int n);
db944f16 1912SR_PRIV GVariant *std_gvar_tuple_rational(const struct sr_rational *r, unsigned int n);
463160cb
UH
1913SR_PRIV GVariant *std_gvar_samplerates(const uint64_t samplerates[], unsigned int n);
1914SR_PRIV GVariant *std_gvar_samplerates_steps(const uint64_t samplerates[], unsigned int n);
54d471f4
UH
1915SR_PRIV GVariant *std_gvar_min_max_step(double min, double max, double step);
1916SR_PRIV GVariant *std_gvar_min_max_step_array(const double a[3]);
7bc3cfe6 1917SR_PRIV GVariant *std_gvar_min_max_step_thresholds(const double dmin, const double dmax, const double dstep);
db944f16 1918
a162eeb2 1919SR_PRIV GVariant *std_gvar_tuple_u64(uint64_t low, uint64_t high);
43995cda 1920SR_PRIV GVariant *std_gvar_tuple_double(double low, double high);
a162eeb2 1921
769561cb
UH
1922SR_PRIV GVariant *std_gvar_array_i32(const int32_t a[], unsigned int n);
1923SR_PRIV GVariant *std_gvar_array_u32(const uint32_t a[], unsigned int n);
1924SR_PRIV GVariant *std_gvar_array_u64(const uint64_t a[], unsigned int n);
70635036 1925SR_PRIV GVariant *std_gvar_array_str(const char *a[], unsigned int n);
db944f16 1926
94e64a0b 1927SR_PRIV GVariant *std_gvar_thresholds(const double a[][2], unsigned int n);
9fb9afb5 1928
697fb6dd
UH
1929SR_PRIV int std_str_idx(GVariant *data, const char *a[], unsigned int n);
1930SR_PRIV int std_u64_idx(GVariant *data, const uint64_t a[], unsigned int n);
1931SR_PRIV int std_u8_idx(GVariant *data, const uint8_t a[], unsigned int n);
1932
1933SR_PRIV int std_str_idx_s(const char *s, const char *a[], unsigned int n);
1934SR_PRIV int std_u8_idx_s(uint8_t b, const uint8_t a[], unsigned int n);
1935
1936SR_PRIV int std_u64_tuple_idx(GVariant *data, const uint64_t a[][2], unsigned int n);
1937SR_PRIV int std_double_tuple_idx(GVariant *data, const double a[][2], unsigned int n);
1938SR_PRIV int std_double_tuple_idx_d0(const double d, const double a[][2], unsigned int n);
1939
fcd6a8bd
UH
1940SR_PRIV int std_cg_idx(const struct sr_channel_group *cg, struct sr_channel_group *a[], unsigned int n);
1941
c0aa074e
UH
1942SR_PRIV int std_dummy_set_params(struct sr_serial_dev_inst *serial,
1943 int baudrate, int bits, int parity, int stopbits,
1944 int flowcontrol, int rts, int dtr);
3ad30b4e
GS
1945SR_PRIV int std_dummy_set_handshake(struct sr_serial_dev_inst *serial,
1946 int rts, int dtr);
c0aa074e 1947
bee24666
DE
1948/*--- resource.c ------------------------------------------------------------*/
1949
7d89fd60
DE
1950SR_PRIV int64_t sr_file_get_size(FILE *file);
1951
bee24666
DE
1952SR_PRIV int sr_resource_open(struct sr_context *ctx,
1953 struct sr_resource *res, int type, const char *name)
1954 G_GNUC_WARN_UNUSED_RESULT;
1955SR_PRIV int sr_resource_close(struct sr_context *ctx,
1956 struct sr_resource *res);
32ba0d80 1957SR_PRIV gssize sr_resource_read(struct sr_context *ctx,
bee24666
DE
1958 const struct sr_resource *res, void *buf, size_t count)
1959 G_GNUC_WARN_UNUSED_RESULT;
1960SR_PRIV void *sr_resource_load(struct sr_context *ctx, int type,
1961 const char *name, size_t *size, size_t max_size)
1962 G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT;
1963
8d558c7a
UH
1964/*--- strutil.c -------------------------------------------------------------*/
1965
1966SR_PRIV int sr_atol(const char *str, long *ret);
97aa41e9 1967SR_PRIV int sr_atol_base(const char *str, long *ret, char **end, int base);
30903c40 1968SR_PRIV int sr_atoul_base(const char *str, unsigned long *ret, char **end, int base);
8d558c7a
UH
1969SR_PRIV int sr_atoi(const char *str, int *ret);
1970SR_PRIV int sr_atod(const char *str, double *ret);
1971SR_PRIV int sr_atof(const char *str, float *ret);
4f0463a0 1972SR_PRIV int sr_atod_ascii(const char *str, double *ret);
91ab2f64 1973SR_PRIV int sr_atod_ascii_digits(const char *str, double *ret, int *digits);
9806c2d5 1974SR_PRIV int sr_atof_ascii(const char *str, float *ret);
8d558c7a 1975
d8bc7ca3
GS
1976SR_PRIV GString *sr_hexdump_new(const uint8_t *data, const size_t len);
1977SR_PRIV void sr_hexdump_free(GString *s);
1978
ac136b57
BV
1979/*--- soft-trigger.c --------------------------------------------------------*/
1980
1981struct soft_trigger_logic {
1982 const struct sr_dev_inst *sdi;
1983 const struct sr_trigger *trigger;
1984 int count;
1985 int unitsize;
1986 int cur_stage;
1987 uint8_t *prev_sample;
fe5a7355
AJ
1988 uint8_t *pre_trigger_buffer;
1989 uint8_t *pre_trigger_head;
1990 int pre_trigger_size;
1991 int pre_trigger_fill;
ac136b57
BV
1992};
1993
d1078180 1994SR_PRIV int logic_channel_unitsize(GSList *channels);
ac136b57 1995SR_PRIV struct soft_trigger_logic *soft_trigger_logic_new(
fe5a7355
AJ
1996 const struct sr_dev_inst *sdi, struct sr_trigger *trigger,
1997 int pre_trigger_samples);
ac136b57
BV
1998SR_PRIV void soft_trigger_logic_free(struct soft_trigger_logic *st);
1999SR_PRIV int soft_trigger_logic_check(struct soft_trigger_logic *st, uint8_t *buf,
fe5a7355 2000 int len, int *pre_trigger_samples);
ac136b57 2001
fcfa36fd 2002/*--- serial.c --------------------------------------------------------------*/
058b7035 2003
1df81f4b 2004#ifdef HAVE_SERIAL_COMM
a54dd31e
UH
2005enum {
2006 SERIAL_RDWR = 1,
2007 SERIAL_RDONLY = 2,
a54dd31e
UH
2008};
2009
144f6660 2010typedef gboolean (*packet_valid_callback)(const uint8_t *buf);
1a7adeac
GS
2011typedef int (*packet_valid_len_callback)(void *st,
2012 const uint8_t *p, size_t l, size_t *pl);
766456be 2013
ae4c1fb6
GS
2014typedef GSList *(*sr_ser_list_append_t)(GSList *devs, const char *name,
2015 const char *desc);
2016typedef GSList *(*sr_ser_find_append_t)(GSList *devs, const char *name);
2017
299bdb24
BV
2018SR_PRIV int serial_open(struct sr_serial_dev_inst *serial, int flags);
2019SR_PRIV int serial_close(struct sr_serial_dev_inst *serial);
2020SR_PRIV int serial_flush(struct sr_serial_dev_inst *serial);
bce75f94 2021SR_PRIV int serial_drain(struct sr_serial_dev_inst *serial);
8c3df6e5 2022SR_PRIV size_t serial_has_receive_data(struct sr_serial_dev_inst *serial);
9a474211 2023SR_PRIV int serial_write_blocking(struct sr_serial_dev_inst *serial,
eead2782 2024 const void *buf, size_t count, unsigned int timeout_ms);
9a474211
ML
2025SR_PRIV int serial_write_nonblocking(struct sr_serial_dev_inst *serial,
2026 const void *buf, size_t count);
9a474211 2027SR_PRIV int serial_read_blocking(struct sr_serial_dev_inst *serial, void *buf,
eead2782 2028 size_t count, unsigned int timeout_ms);
9a474211
ML
2029SR_PRIV int serial_read_nonblocking(struct sr_serial_dev_inst *serial, void *buf,
2030 size_t count);
d4787248
GS
2031SR_PRIV int serial_set_read_chunk_cb(struct sr_serial_dev_inst *serial,
2032 serial_rx_chunk_callback cb, void *cb_data);
299bdb24 2033SR_PRIV int serial_set_params(struct sr_serial_dev_inst *serial, int baudrate,
71caaad4 2034 int bits, int parity, int stopbits, int flowcontrol, int rts, int dtr);
3ad30b4e
GS
2035SR_PRIV int serial_set_handshake(struct sr_serial_dev_inst *serial,
2036 int rts, int dtr);
299bdb24
BV
2037SR_PRIV int serial_set_paramstr(struct sr_serial_dev_inst *serial,
2038 const char *paramstr);
2039SR_PRIV int serial_readline(struct sr_serial_dev_inst *serial, char **buf,
2040 int *buflen, gint64 timeout_ms);
766456be 2041SR_PRIV int serial_stream_detect(struct sr_serial_dev_inst *serial,
1a7adeac
GS
2042 uint8_t *buf, size_t *buflen,
2043 size_t packet_size, packet_valid_callback is_valid,
2044 packet_valid_len_callback is_valid_len, size_t *return_size,
2045 uint64_t timeout_ms);
102f1239
BV
2046SR_PRIV int serial_source_add(struct sr_session *session,
2047 struct sr_serial_dev_inst *serial, int events, int timeout,
2048 sr_receive_data_callback cb, void *cb_data);
2049SR_PRIV int serial_source_remove(struct sr_session *session,
2050 struct sr_serial_dev_inst *serial);
b541f837 2051SR_PRIV GSList *sr_serial_find_usb(uint16_t vendor_id, uint16_t product_id);
c5cfc735 2052SR_PRIV int serial_timeout(struct sr_serial_dev_inst *port, int num_bytes);
ae4c1fb6 2053
ad5aa993
GS
2054SR_PRIV void sr_ser_discard_queued_data(struct sr_serial_dev_inst *serial);
2055SR_PRIV size_t sr_ser_has_queued_data(struct sr_serial_dev_inst *serial);
2056SR_PRIV void sr_ser_queue_rx_data(struct sr_serial_dev_inst *serial,
2057 const uint8_t *data, size_t len);
2058SR_PRIV size_t sr_ser_unqueue_rx_data(struct sr_serial_dev_inst *serial,
2059 uint8_t *data, size_t len);
2060
a7b8692e
GS
2061struct ser_lib_functions {
2062 int (*open)(struct sr_serial_dev_inst *serial, int flags);
2063 int (*close)(struct sr_serial_dev_inst *serial);
2064 int (*flush)(struct sr_serial_dev_inst *serial);
2065 int (*drain)(struct sr_serial_dev_inst *serial);
2066 int (*write)(struct sr_serial_dev_inst *serial,
2067 const void *buf, size_t count,
2068 int nonblocking, unsigned int timeout_ms);
2069 int (*read)(struct sr_serial_dev_inst *serial,
2070 void *buf, size_t count,
2071 int nonblocking, unsigned int timeout_ms);
2072 int (*set_params)(struct sr_serial_dev_inst *serial,
2073 int baudrate, int bits, int parity, int stopbits,
2074 int flowcontrol, int rts, int dtr);
3ad30b4e
GS
2075 int (*set_handshake)(struct sr_serial_dev_inst *serial,
2076 int rts, int dtr);
a7b8692e
GS
2077 int (*setup_source_add)(struct sr_session *session,
2078 struct sr_serial_dev_inst *serial,
2079 int events, int timeout,
2080 sr_receive_data_callback cb, void *cb_data);
2081 int (*setup_source_remove)(struct sr_session *session,
2082 struct sr_serial_dev_inst *serial);
2083 GSList *(*list)(GSList *list, sr_ser_list_append_t append);
2084 GSList *(*find_usb)(GSList *list, sr_ser_find_append_t append,
2085 uint16_t vendor_id, uint16_t product_id);
2086 int (*get_frame_format)(struct sr_serial_dev_inst *serial,
2087 int *baud, int *bits);
2088 size_t (*get_rx_avail)(struct sr_serial_dev_inst *serial);
2089};
2090extern SR_PRIV struct ser_lib_functions *ser_lib_funcs_libsp;
4417074c
GS
2091SR_PRIV int ser_name_is_hid(struct sr_serial_dev_inst *serial);
2092extern SR_PRIV struct ser_lib_functions *ser_lib_funcs_hid;
b79c3422
GS
2093SR_PRIV int ser_name_is_bt(struct sr_serial_dev_inst *serial);
2094extern SR_PRIV struct ser_lib_functions *ser_lib_funcs_bt;
edec0436
GS
2095
2096#ifdef HAVE_LIBHIDAPI
2097struct vid_pid_item {
2098 uint16_t vid, pid;
2099};
edec0436
GS
2100
2101struct ser_hid_chip_functions {
2102 const char *chipname;
2103 const char *chipdesc;
2104 const struct vid_pid_item *vid_pid_items;
2105 const int max_bytes_per_request;
2106 int (*set_params)(struct sr_serial_dev_inst *serial,
2107 int baudrate, int bits, int parity, int stopbits,
2108 int flowcontrol, int rts, int dtr);
2109 int (*read_bytes)(struct sr_serial_dev_inst *serial,
2110 uint8_t *data, int space, unsigned int timeout);
2111 int (*write_bytes)(struct sr_serial_dev_inst *serial,
2112 const uint8_t *data, int space);
2113 int (*flush)(struct sr_serial_dev_inst *serial);
2114 int (*drain)(struct sr_serial_dev_inst *serial);
2115};
a10284cd 2116extern SR_PRIV struct ser_hid_chip_functions *ser_hid_chip_funcs_bu86x;
828eeea2 2117extern SR_PRIV struct ser_hid_chip_functions *ser_hid_chip_funcs_ch9325;
616bc3a1 2118extern SR_PRIV struct ser_hid_chip_functions *ser_hid_chip_funcs_cp2110;
0cdb72c8 2119extern SR_PRIV struct ser_hid_chip_functions *ser_hid_chip_funcs_victor;
edec0436
GS
2120SR_PRIV const char *ser_hid_chip_find_name_vid_pid(uint16_t vid, uint16_t pid);
2121#endif
c4f2dfd0 2122#endif
1483577e 2123
7fd8a8f7
GS
2124SR_PRIV int sr_serial_extract_options(GSList *options,
2125 const char **serial_device, const char **serial_options);
2126
7c8ae47d
GS
2127/*--- bt/ API ---------------------------------------------------------------*/
2128
2129#ifdef HAVE_BLUETOOTH
2130SR_PRIV const char *sr_bt_adapter_get_address(size_t idx);
2131
2132struct sr_bt_desc;
2133typedef void (*sr_bt_scan_cb)(void *cb_data, const char *addr, const char *name);
2134typedef int (*sr_bt_data_cb)(void *cb_data, uint8_t *data, size_t dlen);
2135
2136SR_PRIV struct sr_bt_desc *sr_bt_desc_new(void);
2137SR_PRIV void sr_bt_desc_free(struct sr_bt_desc *desc);
2138
2139SR_PRIV int sr_bt_config_cb_scan(struct sr_bt_desc *desc,
2140 sr_bt_scan_cb cb, void *cb_data);
2141SR_PRIV int sr_bt_config_cb_data(struct sr_bt_desc *desc,
2142 sr_bt_data_cb cb, void *cb_data);
2143SR_PRIV int sr_bt_config_addr_local(struct sr_bt_desc *desc, const char *addr);
2144SR_PRIV int sr_bt_config_addr_remote(struct sr_bt_desc *desc, const char *addr);
2145SR_PRIV int sr_bt_config_rfcomm(struct sr_bt_desc *desc, size_t channel);
2146SR_PRIV int sr_bt_config_notify(struct sr_bt_desc *desc,
2147 uint16_t read_handle, uint16_t write_handle,
2148 uint16_t cccd_handle, uint16_t cccd_value);
2149
2150SR_PRIV int sr_bt_scan_le(struct sr_bt_desc *desc, int duration);
2151SR_PRIV int sr_bt_scan_bt(struct sr_bt_desc *desc, int duration);
2152
2153SR_PRIV int sr_bt_connect_ble(struct sr_bt_desc *desc);
2154SR_PRIV int sr_bt_connect_rfcomm(struct sr_bt_desc *desc);
2155SR_PRIV void sr_bt_disconnect(struct sr_bt_desc *desc);
2156
2157SR_PRIV ssize_t sr_bt_read(struct sr_bt_desc *desc,
2158 void *data, size_t len);
2159SR_PRIV ssize_t sr_bt_write(struct sr_bt_desc *desc,
2160 const void *data, size_t len);
2161
2162SR_PRIV int sr_bt_start_notify(struct sr_bt_desc *desc);
2163SR_PRIV int sr_bt_check_notify(struct sr_bt_desc *desc);
2164#endif
2165
fcfa36fd 2166/*--- ezusb.c ---------------------------------------------------------------*/
058b7035 2167
22b02383 2168#ifdef HAVE_LIBUSB_1_0
1a081ca6 2169SR_PRIV int ezusb_reset(struct libusb_device_handle *hdl, int set_clear);
8e2d6c9d
DE
2170SR_PRIV int ezusb_install_firmware(struct sr_context *ctx, libusb_device_handle *hdl,
2171 const char *name);
2172SR_PRIV int ezusb_upload_firmware(struct sr_context *ctx, libusb_device *dev,
2173 int configuration, const char *name);
22b02383 2174#endif
058b7035 2175
fcfa36fd 2176/*--- usb.c -----------------------------------------------------------------*/
0c632d36 2177
da5286bf
GS
2178SR_PRIV int sr_usb_split_conn(const char *conn,
2179 uint16_t *vid, uint16_t *pid, uint8_t *bus, uint8_t *addr);
0c632d36 2180#ifdef HAVE_LIBUSB_1_0
7ae6a758 2181SR_PRIV GSList *sr_usb_find(libusb_context *usb_ctx, const char *conn);
0c632d36 2182SR_PRIV int sr_usb_open(libusb_context *usb_ctx, struct sr_usb_dev_inst *usb);
67e95ed3 2183SR_PRIV void sr_usb_close(struct sr_usb_dev_inst *usb);
102f1239
BV
2184SR_PRIV int usb_source_add(struct sr_session *session, struct sr_context *ctx,
2185 int timeout, sr_receive_data_callback cb, void *cb_data);
2186SR_PRIV int usb_source_remove(struct sr_session *session, struct sr_context *ctx);
76bc5f63 2187SR_PRIV int usb_get_port_path(libusb_device *dev, char *path, int path_len);
69f7d9b4
JH
2188SR_PRIV gboolean usb_match_manuf_prod(libusb_device *dev,
2189 const char *manufacturer, const char *product);
0c632d36
UH
2190#endif
2191
18698b40
AS
2192/*--- binary_helpers.c ------------------------------------------------------*/
2193
2194/** Binary value type */
2195enum binary_value_type {
d65f51bf
GS
2196 BVT_INVALID,
2197
2198 BVT_UINT8,
18698b40
AS
2199 BVT_BE_UINT8 = BVT_UINT8,
2200 BVT_LE_UINT8 = BVT_UINT8,
2201
2202 BVT_BE_UINT16,
2203 BVT_BE_UINT32,
2204 BVT_BE_UINT64,
2205 BVT_BE_FLOAT,
2206
2207 BVT_LE_UINT16,
2208 BVT_LE_UINT32,
2209 BVT_LE_UINT64,
2210 BVT_LE_FLOAT,
2211};
2212
2213/** Binary value specification */
2214struct binary_value_spec {
e7fe5bb4 2215 size_t offset; /**!< Offset into binary image */
b7721913
GS
2216 enum binary_value_type type; /**!< Data type to decode */
2217 float scale; /**!< Scale factor to native units */
18698b40
AS
2218};
2219
18698b40 2220/**
e7fe5bb4 2221 * Read extract a value from a binary data image.
18698b40 2222 *
b7721913
GS
2223 * @param[out] out Pointer to output buffer (conversion result)
2224 * @param[in] spec Binary value specification
2225 * @param[in] data Pointer to binary input data
2226 * @param[in] length Size of binary input data
2227 *
18698b40
AS
2228 * @return SR_OK on success, SR_ERR_* error code on failure.
2229 */
01671e56
GS
2230SR_PRIV int bv_get_value(float *out, const struct binary_value_spec *spec,
2231 const void *data, size_t length);
18698b40 2232
4ea012bd
AS
2233/*--- crc.c -----------------------------------------------------------------*/
2234
2235#define SR_CRC16_DEFAULT_INIT 0xffffU
2236
2237/**
2238 * Calculate a CRC16 checksum using the 0x8005 polynomial.
2239 *
2240 * This CRC16 flavor is also known as CRC16-ANSI or CRC16-MODBUS.
2241 *
2242 * @param crc Initial value (typically 0xffff)
2243 * @param buffer Input buffer
2244 * @param len Buffer length
2245 * @return Checksum
2246 */
2247SR_PRIV uint16_t sr_crc16(uint16_t crc, const uint8_t *buffer, int len);
2248
daa39012
AJ
2249/*--- modbus/modbus.c -------------------------------------------------------*/
2250
2251struct sr_modbus_dev_inst {
2252 const char *name;
2253 const char *prefix;
2254 int priv_size;
2255 GSList *(*scan)(int modbusaddr);
2256 int (*dev_inst_new)(void *priv, const char *resource,
2257 char **params, const char *serialcomm, int modbusaddr);
2258 int (*open)(void *priv);
2259 int (*source_add)(struct sr_session *session, void *priv, int events,
2260 int timeout, sr_receive_data_callback cb, void *cb_data);
2261 int (*source_remove)(struct sr_session *session, void *priv);
2262 int (*send)(void *priv, const uint8_t *buffer, int buffer_size);
2263 int (*read_begin)(void *priv, uint8_t *function_code);
2264 int (*read_data)(void *priv, uint8_t *buf, int maxlen);
2265 int (*read_end)(void *priv);
2266 int (*close)(void *priv);
2267 void (*free)(void *priv);
2268 unsigned int read_timeout_ms;
2269 void *priv;
2270};
2271
2272SR_PRIV GSList *sr_modbus_scan(struct drv_context *drvc, GSList *options,
2273 struct sr_dev_inst *(*probe_device)(struct sr_modbus_dev_inst *modbus));
2274SR_PRIV struct sr_modbus_dev_inst *modbus_dev_inst_new(const char *resource,
2275 const char *serialcomm, int modbusaddr);
2276SR_PRIV int sr_modbus_open(struct sr_modbus_dev_inst *modbus);
2277SR_PRIV int sr_modbus_source_add(struct sr_session *session,
2278 struct sr_modbus_dev_inst *modbus, int events, int timeout,
2279 sr_receive_data_callback cb, void *cb_data);
2280SR_PRIV int sr_modbus_source_remove(struct sr_session *session,
2281 struct sr_modbus_dev_inst *modbus);
2282SR_PRIV int sr_modbus_request(struct sr_modbus_dev_inst *modbus,
2283 uint8_t *request, int request_size);
2284SR_PRIV int sr_modbus_reply(struct sr_modbus_dev_inst *modbus,
2285 uint8_t *reply, int reply_size);
2286SR_PRIV int sr_modbus_request_reply(struct sr_modbus_dev_inst *modbus,
2287 uint8_t *request, int request_size,
2288 uint8_t *reply, int reply_size);
2289SR_PRIV int sr_modbus_read_coils(struct sr_modbus_dev_inst *modbus,
2290 int address, int nb_coils, uint8_t *coils);
2291SR_PRIV int sr_modbus_read_holding_registers(struct sr_modbus_dev_inst *modbus,
2292 int address, int nb_registers,
2293 uint16_t *registers);
2294SR_PRIV int sr_modbus_write_coil(struct sr_modbus_dev_inst *modbus,
2295 int address, int value);
2296SR_PRIV int sr_modbus_write_multiple_registers(struct sr_modbus_dev_inst*modbus,
2297 int address, int nb_registers,
2298 uint16_t *registers);
2299SR_PRIV int sr_modbus_close(struct sr_modbus_dev_inst *modbus);
2300SR_PRIV void sr_modbus_free(struct sr_modbus_dev_inst *modbus);
2301
fcfa36fd 2302/*--- dmm/es519xx.c ---------------------------------------------------------*/
c01bdebc 2303
bfb926c1
AJ
2304/**
2305 * All 11-byte es519xx chips repeat each block twice for each conversion cycle
2306 * so always read 2 blocks at a time.
2307 */
2308#define ES519XX_11B_PACKET_SIZE (11 * 2)
72e1672f 2309#define ES519XX_14B_PACKET_SIZE 14
c01bdebc
AJ
2310
2311struct es519xx_info {
2312 gboolean is_judge, is_voltage, is_auto, is_micro, is_current;
2313 gboolean is_milli, is_resistance, is_continuity, is_diode;
2314 gboolean is_frequency, is_rpm, is_capacitance, is_duty_cycle;
2315 gboolean is_temperature, is_celsius, is_fahrenheit;
2316 gboolean is_adp0, is_adp1, is_adp2, is_adp3;
2317 gboolean is_sign, is_batt, is_ol, is_pmax, is_pmin, is_apo;
2318 gboolean is_dc, is_ac, is_vahz, is_min, is_max, is_rel, is_hold;
2319 gboolean is_digit4, is_ul, is_vasel, is_vbar, is_lpf1, is_lpf0, is_rmr;
2320 uint32_t baudrate;
2321 int packet_size;
2322 gboolean alt_functions, fivedigits, clampmeter, selectable_lpf;
8cbf5627 2323 int digits;
c01bdebc
AJ
2324};
2325
72e1672f
UH
2326SR_PRIV gboolean sr_es519xx_2400_11b_packet_valid(const uint8_t *buf);
2327SR_PRIV int sr_es519xx_2400_11b_parse(const uint8_t *buf, float *floatval,
8c677240 2328 struct sr_datafeed_analog *analog, void *info);
2588e50c
AJ
2329SR_PRIV gboolean sr_es519xx_2400_11b_altfn_packet_valid(const uint8_t *buf);
2330SR_PRIV int sr_es519xx_2400_11b_altfn_parse(const uint8_t *buf,
8c677240 2331 float *floatval, struct sr_datafeed_analog *analog, void *info);
72e1672f 2332SR_PRIV gboolean sr_es519xx_19200_11b_5digits_packet_valid(const uint8_t *buf);
93d719cd 2333SR_PRIV int sr_es519xx_19200_11b_5digits_parse(const uint8_t *buf,
8c677240 2334 float *floatval, struct sr_datafeed_analog *analog, void *info);
72e1672f
UH
2335SR_PRIV gboolean sr_es519xx_19200_11b_clamp_packet_valid(const uint8_t *buf);
2336SR_PRIV int sr_es519xx_19200_11b_clamp_parse(const uint8_t *buf,
8c677240 2337 float *floatval, struct sr_datafeed_analog *analog, void *info);
72e1672f
UH
2338SR_PRIV gboolean sr_es519xx_19200_11b_packet_valid(const uint8_t *buf);
2339SR_PRIV int sr_es519xx_19200_11b_parse(const uint8_t *buf, float *floatval,
8c677240 2340 struct sr_datafeed_analog *analog, void *info);
72e1672f
UH
2341SR_PRIV gboolean sr_es519xx_19200_14b_packet_valid(const uint8_t *buf);
2342SR_PRIV int sr_es519xx_19200_14b_parse(const uint8_t *buf, float *floatval,
8c677240 2343 struct sr_datafeed_analog *analog, void *info);
72e1672f
UH
2344SR_PRIV gboolean sr_es519xx_19200_14b_sel_lpf_packet_valid(const uint8_t *buf);
2345SR_PRIV int sr_es519xx_19200_14b_sel_lpf_parse(const uint8_t *buf,
8c677240 2346 float *floatval, struct sr_datafeed_analog *analog, void *info);
c01bdebc 2347
fcfa36fd 2348/*--- dmm/fs9922.c ----------------------------------------------------------*/
79081ec8 2349
913abe83
UH
2350#define FS9922_PACKET_SIZE 14
2351
2352struct fs9922_info {
2353 gboolean is_auto, is_dc, is_ac, is_rel, is_hold, is_bpn, is_z1, is_z2;
2354 gboolean is_max, is_min, is_apo, is_bat, is_nano, is_z3, is_micro;
2355 gboolean is_milli, is_kilo, is_mega, is_beep, is_diode, is_percent;
2356 gboolean is_z4, is_volt, is_ampere, is_ohm, is_hfe, is_hertz, is_farad;
2357 gboolean is_celsius, is_fahrenheit;
2358 int bargraph_sign, bargraph_value;
2359};
2360
913abe83
UH
2361SR_PRIV gboolean sr_fs9922_packet_valid(const uint8_t *buf);
2362SR_PRIV int sr_fs9922_parse(const uint8_t *buf, float *floatval,
8c677240
UH
2363 struct sr_datafeed_analog *analog, void *info);
2364SR_PRIV void sr_fs9922_z1_diode(struct sr_datafeed_analog *analog, void *info);
79081ec8 2365
fcfa36fd 2366/*--- dmm/fs9721.c ----------------------------------------------------------*/
6c701476 2367
8c1adf37
UH
2368#define FS9721_PACKET_SIZE 14
2369
2370struct fs9721_info {
2371 gboolean is_ac, is_dc, is_auto, is_rs232, is_micro, is_nano, is_kilo;
2372 gboolean is_diode, is_milli, is_percent, is_mega, is_beep, is_farad;
2373 gboolean is_ohm, is_rel, is_hold, is_ampere, is_volt, is_hz, is_bat;
2374 gboolean is_c2c1_11, is_c2c1_10, is_c2c1_01, is_c2c1_00, is_sign;
2375};
2376
8c1adf37
UH
2377SR_PRIV gboolean sr_fs9721_packet_valid(const uint8_t *buf);
2378SR_PRIV int sr_fs9721_parse(const uint8_t *buf, float *floatval,
8c677240
UH
2379 struct sr_datafeed_analog *analog, void *info);
2380SR_PRIV void sr_fs9721_00_temp_c(struct sr_datafeed_analog *analog, void *info);
2381SR_PRIV void sr_fs9721_01_temp_c(struct sr_datafeed_analog *analog, void *info);
2382SR_PRIV void sr_fs9721_10_temp_c(struct sr_datafeed_analog *analog, void *info);
2383SR_PRIV void sr_fs9721_01_10_temp_f_c(struct sr_datafeed_analog *analog, void *info);
2384SR_PRIV void sr_fs9721_max_c_min(struct sr_datafeed_analog *analog, void *info);
dcd212f7 2385
4c29bba1
PS
2386/*--- dmm/mm38xr.c ---------------------------------------------------------*/
2387
2388#define METERMAN_38XR_PACKET_SIZE 15
2389
2390struct meterman_38xr_info { int dummy; };
2391
2392SR_PRIV gboolean meterman_38xr_packet_valid(const uint8_t *buf);
2393SR_PRIV int meterman_38xr_parse(const uint8_t *buf, float *floatval,
2394 struct sr_datafeed_analog *analog, void *info);
2395
dcd212f7
VV
2396/*--- dmm/ms2115b.c ---------------------------------------------------------*/
2397
2398#define MS2115B_PACKET_SIZE 9
2399
2400enum ms2115b_display {
2401 MS2115B_DISPLAY_MAIN,
2402 MS2115B_DISPLAY_SUB,
2403 MS2115B_DISPLAY_COUNT,
2404};
2405
2406struct ms2115b_info {
2407 /* Selected channel. */
2408 size_t ch_idx;
2409 gboolean is_ac, is_dc, is_auto;
2410 gboolean is_diode, is_beep, is_farad;
2411 gboolean is_ohm, is_ampere, is_volt, is_hz;
2412 gboolean is_duty_cycle, is_percent;
2413};
2414
2415extern SR_PRIV const char *ms2115b_channel_formats[];
2416SR_PRIV gboolean sr_ms2115b_packet_valid(const uint8_t *buf);
2417SR_PRIV int sr_ms2115b_parse(const uint8_t *buf, float *floatval,
2418 struct sr_datafeed_analog *analog, void *info);
6c701476 2419
fcfa36fd 2420/*--- dmm/ms8250d.c ---------------------------------------------------------*/
67070942
M
2421
2422#define MS8250D_PACKET_SIZE 18
2423
2424struct ms8250d_info {
2425 gboolean is_ac, is_dc, is_auto, is_rs232, is_micro, is_nano, is_kilo;
2426 gboolean is_diode, is_milli, is_percent, is_mega, is_beep, is_farad;
2427 gboolean is_ohm, is_rel, is_hold, is_ampere, is_volt, is_hz, is_bat;
2428 gboolean is_ncv, is_min, is_max, is_sign, is_autotimer;
2429};
2430
2431SR_PRIV gboolean sr_ms8250d_packet_valid(const uint8_t *buf);
2432SR_PRIV int sr_ms8250d_parse(const uint8_t *buf, float *floatval,
2433 struct sr_datafeed_analog *analog, void *info);
2434
fcfa36fd 2435/*--- dmm/dtm0660.c ---------------------------------------------------------*/
eed3dec8
MG
2436
2437#define DTM0660_PACKET_SIZE 15
2438
2439struct dtm0660_info {
2440 gboolean is_ac, is_dc, is_auto, is_rs232, is_micro, is_nano, is_kilo;
2441 gboolean is_diode, is_milli, is_percent, is_mega, is_beep, is_farad;
2442 gboolean is_ohm, is_rel, is_hold, is_ampere, is_volt, is_hz, is_bat;
2443 gboolean is_degf, is_degc, is_c2c1_01, is_c2c1_00, is_apo, is_min;
2444 gboolean is_minmax, is_max, is_sign;
2445};
2446
2447SR_PRIV gboolean sr_dtm0660_packet_valid(const uint8_t *buf);
2448SR_PRIV int sr_dtm0660_parse(const uint8_t *buf, float *floatval,
8c677240 2449 struct sr_datafeed_analog *analog, void *info);
eed3dec8 2450
fcfa36fd 2451/*--- dmm/m2110.c -----------------------------------------------------------*/
825da8b2
MH
2452
2453#define BBCGM_M2110_PACKET_SIZE 9
2454
9d12555f
UH
2455/* Dummy info struct. The parser does not use it. */
2456struct m2110_info { int dummy; };
2457
825da8b2
MH
2458SR_PRIV gboolean sr_m2110_packet_valid(const uint8_t *buf);
2459SR_PRIV int sr_m2110_parse(const uint8_t *buf, float *floatval,
8c677240 2460 struct sr_datafeed_analog *analog, void *info);
825da8b2 2461
fcfa36fd 2462/*--- dmm/metex14.c ---------------------------------------------------------*/
ac913e5c
UH
2463
2464#define METEX14_PACKET_SIZE 14
2465
2466struct metex14_info {
556a926d 2467 size_t ch_idx;
ac913e5c
UH
2468 gboolean is_ac, is_dc, is_resistance, is_capacity, is_temperature;
2469 gboolean is_diode, is_frequency, is_ampere, is_volt, is_farad;
7fb4ff02
FS
2470 gboolean is_hertz, is_ohm, is_celsius, is_fahrenheit, is_watt;
2471 gboolean is_pico, is_nano, is_micro, is_milli, is_kilo, is_mega;
fd8dc1db 2472 gboolean is_gain, is_decibel, is_power, is_decibel_mw, is_power_factor;
7fb4ff02 2473 gboolean is_hfe, is_unitless, is_logic, is_min, is_max, is_avg;
ac913e5c
UH
2474};
2475
1df81f4b 2476#ifdef HAVE_SERIAL_COMM
ce3777ad 2477SR_PRIV int sr_metex14_packet_request(struct sr_serial_dev_inst *serial);
c4f2dfd0 2478#endif
ac913e5c
UH
2479SR_PRIV gboolean sr_metex14_packet_valid(const uint8_t *buf);
2480SR_PRIV int sr_metex14_parse(const uint8_t *buf, float *floatval,
8c677240 2481 struct sr_datafeed_analog *analog, void *info);
556a926d
GS
2482SR_PRIV gboolean sr_metex14_4packets_valid(const uint8_t *buf);
2483SR_PRIV int sr_metex14_4packets_parse(const uint8_t *buf, float *floatval,
2484 struct sr_datafeed_analog *analog, void *info);
ac913e5c 2485
fcfa36fd 2486/*--- dmm/rs9lcd.c ----------------------------------------------------------*/
05f134ab 2487
21829e67 2488#define RS9LCD_PACKET_SIZE 9
05f134ab 2489
e7ed87a4 2490/* Dummy info struct. The parser does not use it. */
bf6f8399 2491struct rs9lcd_info { int dummy; };
e7ed87a4 2492
05f134ab
AG
2493SR_PRIV gboolean sr_rs9lcd_packet_valid(const uint8_t *buf);
2494SR_PRIV int sr_rs9lcd_parse(const uint8_t *buf, float *floatval,
8c677240 2495 struct sr_datafeed_analog *analog, void *info);
05f134ab 2496
fcfa36fd 2497/*--- dmm/bm25x.c -----------------------------------------------------------*/
a24c3f4a
JH
2498
2499#define BRYMEN_BM25X_PACKET_SIZE 15
2500
2501/* Dummy info struct. The parser does not use it. */
2502struct bm25x_info { int dummy; };
2503
2504SR_PRIV gboolean sr_brymen_bm25x_packet_valid(const uint8_t *buf);
2505SR_PRIV int sr_brymen_bm25x_parse(const uint8_t *buf, float *floatval,
8c677240 2506 struct sr_datafeed_analog *analog, void *info);
a24c3f4a 2507
400bc4ff
GS
2508/*--- dmm/bm52x.c -----------------------------------------------------------*/
2509
2510#define BRYMEN_BM52X_PACKET_SIZE 24
2511#define BRYMEN_BM52X_DISPLAY_COUNT 2
2512
2513struct brymen_bm52x_info { size_t ch_idx; };
2514
2515#ifdef HAVE_SERIAL_COMM
2516SR_PRIV int sr_brymen_bm52x_packet_request(struct sr_serial_dev_inst *serial);
6bee394d 2517SR_PRIV int sr_brymen_bm82x_packet_request(struct sr_serial_dev_inst *serial);
400bc4ff
GS
2518#endif
2519SR_PRIV gboolean sr_brymen_bm52x_packet_valid(const uint8_t *buf);
6bee394d
GS
2520SR_PRIV gboolean sr_brymen_bm82x_packet_valid(const uint8_t *buf);
2521/* BM520s and BM820s protocols are similar, the parse routine is shared. */
400bc4ff
GS
2522SR_PRIV int sr_brymen_bm52x_parse(const uint8_t *buf, float *floatval,
2523 struct sr_datafeed_analog *analog, void *info);
2524
0931639a
GS
2525struct brymen_bm52x_state;
2526
2527SR_PRIV void *brymen_bm52x_state_init(void);
2528SR_PRIV void brymen_bm52x_state_free(void *state);
2529SR_PRIV int brymen_bm52x_config_get(void *state, uint32_t key, GVariant **data,
2530 const struct sr_dev_inst *sdi, const struct sr_channel_group *cg);
2531SR_PRIV int brymen_bm52x_config_set(void *state, uint32_t key, GVariant *data,
2532 const struct sr_dev_inst *sdi, const struct sr_channel_group *cg);
2533SR_PRIV int brymen_bm52x_config_list(void *state, uint32_t key, GVariant **data,
2534 const struct sr_dev_inst *sdi, const struct sr_channel_group *cg);
2535SR_PRIV int brymen_bm52x_acquire_start(void *state,
2536 const struct sr_dev_inst *sdi,
2537 sr_receive_data_callback *cb, void **cb_data);
2538
27186eda
GS
2539/*--- dmm/bm85x.c -----------------------------------------------------------*/
2540
2541#define BRYMEN_BM85x_PACKET_SIZE_MIN 4
2542
2543struct brymen_bm85x_info { int dummy; };
2544
2545#ifdef HAVE_SERIAL_COMM
2546SR_PRIV int brymen_bm85x_after_open(struct sr_serial_dev_inst *serial);
2547SR_PRIV int brymen_bm85x_packet_request(struct sr_serial_dev_inst *serial);
2548#endif
2549SR_PRIV gboolean brymen_bm85x_packet_valid(void *state,
2550 const uint8_t *buf, size_t len, size_t *pkt_len);
2551SR_PRIV int brymen_bm85x_parse(void *state, const uint8_t *buf, size_t len,
2552 double *floatval, struct sr_datafeed_analog *analog, void *info);
2553
0759e2f5
GS
2554/*--- dmm/bm86x.c -----------------------------------------------------------*/
2555
2556#define BRYMEN_BM86X_PACKET_SIZE 24
2557#define BRYMEN_BM86X_DISPLAY_COUNT 2
2558
2559struct brymen_bm86x_info { size_t ch_idx; };
2560
2561#ifdef HAVE_SERIAL_COMM
2562SR_PRIV int sr_brymen_bm86x_packet_request(struct sr_serial_dev_inst *serial);
2563#endif
2564SR_PRIV gboolean sr_brymen_bm86x_packet_valid(const uint8_t *buf);
2565SR_PRIV int sr_brymen_bm86x_parse(const uint8_t *buf, float *floatval,
2566 struct sr_datafeed_analog *analog, void *info);
2567
fcfa36fd 2568/*--- dmm/ut71x.c -----------------------------------------------------------*/
626027df
UH
2569
2570#define UT71X_PACKET_SIZE 11
2571
2572struct ut71x_info {
2573 gboolean is_voltage, is_resistance, is_capacitance, is_temperature;
2574 gboolean is_celsius, is_fahrenheit, is_current, is_continuity;
2575 gboolean is_diode, is_frequency, is_duty_cycle, is_dc, is_ac;
2576 gboolean is_auto, is_manual, is_sign, is_power, is_loop_current;
2577};
2578
2579SR_PRIV gboolean sr_ut71x_packet_valid(const uint8_t *buf);
2580SR_PRIV int sr_ut71x_parse(const uint8_t *buf, float *floatval,
8c677240 2581 struct sr_datafeed_analog *analog, void *info);
626027df 2582
fcfa36fd 2583/*--- dmm/vc870.c -----------------------------------------------------------*/
c36f78f7
UH
2584
2585#define VC870_PACKET_SIZE 23
2586
2587struct vc870_info {
2588 gboolean is_voltage, is_dc, is_ac, is_temperature, is_resistance;
2589 gboolean is_continuity, is_capacitance, is_diode, is_loop_current;
2590 gboolean is_current, is_micro, is_milli, is_power;
ee2e9be2 2591 gboolean is_power_factor_freq, is_power_apparent_power, is_v_a_rms_value;
c36f78f7
UH
2592 gboolean is_sign2, is_sign1, is_batt, is_ol1, is_max, is_min;
2593 gboolean is_maxmin, is_rel, is_ol2, is_open, is_manu, is_hold;
2594 gboolean is_light, is_usb, is_warning, is_auto_power, is_misplug_warn;
2595 gboolean is_lo, is_hi, is_open2;
2596
3591481e 2597 gboolean is_frequency, is_dual_display, is_auto;
c36f78f7
UH
2598};
2599
2600SR_PRIV gboolean sr_vc870_packet_valid(const uint8_t *buf);
2601SR_PRIV int sr_vc870_parse(const uint8_t *buf, float *floatval,
8c677240 2602 struct sr_datafeed_analog *analog, void *info);
c36f78f7 2603
fcfa36fd 2604/*--- dmm/vc96.c ------------------------------------------------------------*/
9456d636
MS
2605
2606#define VC96_PACKET_SIZE 13
2607
2608struct vc96_info {
2609 size_t ch_idx;
2610 gboolean is_ac, is_dc, is_resistance, is_diode, is_ampere, is_volt;
2611 gboolean is_ohm, is_micro, is_milli, is_kilo, is_mega, is_hfe;
2612 gboolean is_unitless;
2613};
2614
2615SR_PRIV gboolean sr_vc96_packet_valid(const uint8_t *buf);
2616SR_PRIV int sr_vc96_parse(const uint8_t *buf, float *floatval,
2617 struct sr_datafeed_analog *analog, void *info);
2618
fcfa36fd 2619/*--- lcr/es51919.c ---------------------------------------------------------*/
6bcb3ee8 2620
bf5c4d46
GS
2621/* Acquisition details which apply to all supported serial-lcr devices. */
2622struct lcr_parse_info {
2623 size_t ch_idx;
2624 uint64_t output_freq;
2625 const char *circuit_model;
2626};
2627
2628#define ES51919_PACKET_SIZE 17
2629#define ES51919_CHANNEL_COUNT 2
2630#define ES51919_COMM_PARAM "9600/8n1/rts=1/dtr=1"
2631
2632SR_PRIV int es51919_config_get(uint32_t key, GVariant **data,
2633 const struct sr_dev_inst *sdi, const struct sr_channel_group *cg);
2634SR_PRIV int es51919_config_set(uint32_t key, GVariant *data,
2635 const struct sr_dev_inst *sdi, const struct sr_channel_group *cg);
2636SR_PRIV int es51919_config_list(uint32_t key, GVariant **data,
2637 const struct sr_dev_inst *sdi, const struct sr_channel_group *cg);
2638SR_PRIV gboolean es51919_packet_valid(const uint8_t *pkt);
2639SR_PRIV int es51919_packet_parse(const uint8_t *pkt, float *floatval,
b50970a5
GS
2640 struct sr_datafeed_analog *analog, void *info);
2641
2642/*--- lcr/vc4080.c ----------------------------------------------------------*/
2643
2644/* Note: Also uses 'struct lcr_parse_info' from es51919 above. */
2645
2646#define VC4080_PACKET_SIZE 39
2647#define VC4080_COMM_PARAM "1200/8n1"
2648#define VC4080_WITH_DQ_CHANS 0 /* Enable separate D/Q channels? */
2649
2650enum vc4080_display {
2651 VC4080_DISPLAY_PRIMARY,
2652 VC4080_DISPLAY_SECONDARY,
2653#if VC4080_WITH_DQ_CHANS
2654 VC4080_DISPLAY_D_VALUE,
2655 VC4080_DISPLAY_Q_VALUE,
2656#endif
2657 VC4080_CHANNEL_COUNT,
2658};
2659
2660extern SR_PRIV const char *vc4080_channel_formats[VC4080_CHANNEL_COUNT];
2661
2662SR_PRIV int vc4080_config_list(uint32_t key, GVariant **data,
2663 const struct sr_dev_inst *sdi, const struct sr_channel_group *cg);
2664SR_PRIV int vc4080_packet_request(struct sr_serial_dev_inst *serial);
2665SR_PRIV gboolean vc4080_packet_valid(const uint8_t *pkt);
2666SR_PRIV int vc4080_packet_parse(const uint8_t *pkt, float *floatval,
bf5c4d46 2667 struct sr_datafeed_analog *analog, void *info);
6bcb3ee8 2668
fcfa36fd 2669/*--- dmm/ut372.c -----------------------------------------------------------*/
f3cde309
ML
2670
2671#define UT372_PACKET_SIZE 27
2672
2673struct ut372_info {
2674 int dummy;
2675};
2676
2677SR_PRIV gboolean sr_ut372_packet_valid(const uint8_t *buf);
2678SR_PRIV int sr_ut372_parse(const uint8_t *buf, float *floatval,
8c677240 2679 struct sr_datafeed_analog *analog, void *info);
f3cde309 2680
fcfa36fd 2681/*--- dmm/asycii.c ----------------------------------------------------------*/
4ba4d52a
GS
2682
2683#define ASYCII_PACKET_SIZE 16
2684
2685struct asycii_info {
2686 gboolean is_ac, is_dc, is_ac_and_dc;
2687 gboolean is_resistance, is_capacitance, is_diode, is_gain;
2688 gboolean is_frequency, is_duty_cycle, is_duty_pos, is_duty_neg;
2689 gboolean is_pulse_width, is_period_pos, is_period_neg;
2690 gboolean is_pulse_count, is_count_pos, is_count_neg;
2691 gboolean is_ampere, is_volt, is_volt_ampere, is_farad, is_ohm;
2692 gboolean is_hertz, is_percent, is_seconds, is_decibel;
2693 gboolean is_pico, is_nano, is_micro, is_milli, is_kilo, is_mega;
2694 gboolean is_unitless;
2695 gboolean is_peak_min, is_peak_max;
2696 gboolean is_invalid;
2697};
2698
1df81f4b 2699#ifdef HAVE_SERIAL_COMM
4ba4d52a
GS
2700SR_PRIV int sr_asycii_packet_request(struct sr_serial_dev_inst *serial);
2701#endif
2702SR_PRIV gboolean sr_asycii_packet_valid(const uint8_t *buf);
2703SR_PRIV int sr_asycii_parse(const uint8_t *buf, float *floatval,
2704 struct sr_datafeed_analog *analog, void *info);
2705
fcfa36fd 2706/*--- dmm/eev121gw.c --------------------------------------------------------*/
1c3098aa
GS
2707
2708#define EEV121GW_PACKET_SIZE 19
2709
2710enum eev121gw_display {
2711 EEV121GW_DISPLAY_MAIN,
2712 EEV121GW_DISPLAY_SUB,
2713 EEV121GW_DISPLAY_BAR,
2714 EEV121GW_DISPLAY_COUNT,
2715};
2716
2717struct eev121gw_info {
2718 /* Selected channel. */
2719 size_t ch_idx;
2720 /*
2721 * Measured value, number and sign/overflow flags, scale factor
2722 * and significant digits.
2723 */
2724 uint32_t uint_value;
2725 gboolean is_ofl, is_neg;
2726 int factor, digits;
2727 /* Currently active mode (meter's function). */
2728 gboolean is_ac, is_dc, is_voltage, is_current, is_power, is_gain;
2729 gboolean is_resistance, is_capacitance, is_diode, is_temperature;
2730 gboolean is_continuity, is_frequency, is_period, is_duty_cycle;
2731 /* Quantities associated with mode/function. */
2732 gboolean is_ampere, is_volt, is_volt_ampere, is_dbm;
2733 gboolean is_ohm, is_farad, is_celsius, is_fahrenheit;
2734 gboolean is_hertz, is_seconds, is_percent, is_loop_current;
2735 gboolean is_unitless, is_logic;
2736 /* Other indicators. */
2737 gboolean is_min, is_max, is_avg, is_1ms_peak, is_rel, is_hold;
2738 gboolean is_low_pass, is_mem, is_bt, is_auto_range, is_test;
2739 gboolean is_auto_poweroff, is_low_batt;
2740};
2741
015df4ae 2742extern SR_PRIV const char *eev121gw_channel_formats[];
1c3098aa 2743SR_PRIV gboolean sr_eev121gw_packet_valid(const uint8_t *buf);
1c3098aa 2744SR_PRIV int sr_eev121gw_3displays_parse(const uint8_t *buf, float *floatval,
8556703a 2745 struct sr_datafeed_analog *analog, void *info);
1c3098aa 2746
fcfa36fd 2747/*--- scale/kern.c ----------------------------------------------------------*/
e5d953b5
UH
2748
2749struct kern_info {
2750 gboolean is_gram, is_carat, is_ounce, is_pound, is_troy_ounce;
2751 gboolean is_pennyweight, is_grain, is_tael, is_momme, is_tola;
2752 gboolean is_percentage, is_piece, is_unstable, is_stable, is_error;
2753 int buflen;
2754};
2755
2756SR_PRIV gboolean sr_kern_packet_valid(const uint8_t *buf);
2757SR_PRIV int sr_kern_parse(const uint8_t *buf, float *floatval,
563ba4a5 2758 struct sr_datafeed_analog *analog, void *info);
e5d953b5 2759
aea4e458
LPC
2760/*--- sw_limits.c -----------------------------------------------------------*/
2761
2762struct sr_sw_limits {
2763 uint64_t limit_samples;
67785f25 2764 uint64_t limit_frames;
aea4e458
LPC
2765 uint64_t limit_msec;
2766 uint64_t samples_read;
67785f25 2767 uint64_t frames_read;
aea4e458
LPC
2768 uint64_t start_time;
2769};
2770
d579755a 2771SR_PRIV int sr_sw_limits_config_get(const struct sr_sw_limits *limits, uint32_t key,
aea4e458
LPC
2772 GVariant **data);
2773SR_PRIV int sr_sw_limits_config_set(struct sr_sw_limits *limits, uint32_t key,
2774 GVariant *data);
2775SR_PRIV void sr_sw_limits_acquisition_start(struct sr_sw_limits *limits);
2776SR_PRIV gboolean sr_sw_limits_check(struct sr_sw_limits *limits);
5aba93c3
GS
2777SR_PRIV int sr_sw_limits_get_remain(const struct sr_sw_limits *limits,
2778 uint64_t *samples, uint64_t *frames, uint64_t *msecs,
2779 gboolean *exceeded);
aea4e458
LPC
2780SR_PRIV void sr_sw_limits_update_samples_read(struct sr_sw_limits *limits,
2781 uint64_t samples_read);
67785f25
GS
2782SR_PRIV void sr_sw_limits_update_frames_read(struct sr_sw_limits *limits,
2783 uint64_t frames_read);
aea4e458
LPC
2784SR_PRIV void sr_sw_limits_init(struct sr_sw_limits *limits);
2785
47a102f9
GS
2786/*--- feed_queue.h ----------------------------------------------------------*/
2787
2788struct feed_queue_logic;
2789struct feed_queue_analog;
2790
2791SR_API struct feed_queue_logic *feed_queue_logic_alloc(
57140e5a 2792 const struct sr_dev_inst *sdi,
47a102f9
GS
2793 size_t sample_count, size_t unit_size);
2794SR_API int feed_queue_logic_submit(struct feed_queue_logic *q,
2795 const uint8_t *data, size_t count);
2796SR_API int feed_queue_logic_flush(struct feed_queue_logic *q);
f478c3e6 2797SR_API int feed_queue_logic_send_trigger(struct feed_queue_logic *q);
47a102f9
GS
2798SR_API void feed_queue_logic_free(struct feed_queue_logic *q);
2799
2800SR_API struct feed_queue_analog *feed_queue_analog_alloc(
57140e5a 2801 const struct sr_dev_inst *sdi,
47a102f9 2802 size_t sample_count, int digits, struct sr_channel *ch);
cc8b162f 2803SR_API int feed_queue_analog_mq_unit(struct feed_queue_analog *q,
43e6f7a7 2804 enum sr_mq mq, enum sr_mqflag mq_flag, enum sr_unit unit);
cc8b162f
GS
2805SR_API int feed_queue_analog_scale_offset(struct feed_queue_analog *q,
2806 const struct sr_rational *scale, const struct sr_rational *offset);
47a102f9
GS
2807SR_API int feed_queue_analog_submit(struct feed_queue_analog *q,
2808 float data, size_t count);
2809SR_API int feed_queue_analog_flush(struct feed_queue_analog *q);
2810SR_API void feed_queue_analog_free(struct feed_queue_analog *q);
2811
1483577e 2812#endif