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