libsigrok  0.5.2
sigrok hardware access and backend library
analog.c
Go to the documentation of this file.
1 /*
2  * This file is part of the libsigrok project.
3  *
4  * Copyright (C) 2014 Bert Vermeulen <bert@biot.com>
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 
20 #include <config.h>
21 #include <stdio.h>
22 #include <stdint.h>
23 #include <string.h>
24 #include <ctype.h>
25 #include <math.h>
26 #include <libsigrok/libsigrok.h>
27 #include "libsigrok-internal.h"
28 
29 /** @cond PRIVATE */
30 #define LOG_PREFIX "analog"
31 /** @endcond */
32 
33 /**
34  * @file
35  *
36  * Handling and converting analog data.
37  */
38 
39 /**
40  * @defgroup grp_analog Analog data handling
41  *
42  * Handling and converting analog data.
43  *
44  * @{
45  */
46 
47 struct unit_mq_string {
48  uint64_t value;
49  const char *str;
50 };
51 
52 /* Please use the same order as in enum sr_unit (libsigrok.h). */
53 static struct unit_mq_string unit_strings[] = {
54  { SR_UNIT_VOLT, "V" },
55  { SR_UNIT_AMPERE, "A" },
56  { SR_UNIT_OHM, "\xe2\x84\xa6" },
57  { SR_UNIT_FARAD, "F" },
58  { SR_UNIT_KELVIN, "K" },
59  { SR_UNIT_CELSIUS, "\xc2\xb0""C" },
60  { SR_UNIT_FAHRENHEIT, "\xc2\xb0""F" },
61  { SR_UNIT_HERTZ, "Hz" },
62  { SR_UNIT_PERCENTAGE, "%" },
63  { SR_UNIT_BOOLEAN, "" },
64  { SR_UNIT_SECOND, "s" },
65  { SR_UNIT_SIEMENS, "S" },
66  { SR_UNIT_DECIBEL_MW, "dBm" },
67  { SR_UNIT_DECIBEL_VOLT, "dBV" },
68  { SR_UNIT_UNITLESS, "" },
69  { SR_UNIT_DECIBEL_SPL, "dB" },
70  { SR_UNIT_CONCENTRATION, "ppm" },
72  { SR_UNIT_VOLT_AMPERE, "VA" },
73  { SR_UNIT_WATT, "W" },
74  { SR_UNIT_WATT_HOUR, "Wh" },
75  { SR_UNIT_METER_SECOND, "m/s" },
76  { SR_UNIT_HECTOPASCAL, "hPa" },
77  { SR_UNIT_HUMIDITY_293K, "%rF" },
78  { SR_UNIT_DEGREE, "\xc2\xb0" },
79  { SR_UNIT_HENRY, "H" },
80  { SR_UNIT_GRAM, "g" },
81  { SR_UNIT_CARAT, "ct" },
82  { SR_UNIT_OUNCE, "oz" },
83  { SR_UNIT_TROY_OUNCE, "oz t" },
84  { SR_UNIT_POUND, "lb" },
85  { SR_UNIT_PENNYWEIGHT, "dwt" },
86  { SR_UNIT_GRAIN, "gr" },
87  { SR_UNIT_TAEL, "tael" },
88  { SR_UNIT_MOMME, "momme" },
89  { SR_UNIT_TOLA, "tola" },
90  { SR_UNIT_PIECE, "pcs" },
91  ALL_ZERO
92 };
93 
94 /* Please use the same order as in enum sr_mqflag (libsigrok.h). */
95 static struct unit_mq_string mq_strings[] = {
96  { SR_MQFLAG_AC, " AC" },
97  { SR_MQFLAG_DC, " DC" },
98  { SR_MQFLAG_RMS, " RMS" },
99  { SR_MQFLAG_DIODE, " DIODE" },
100  { SR_MQFLAG_HOLD, " HOLD" },
101  { SR_MQFLAG_MAX, " MAX" },
102  { SR_MQFLAG_MIN, " MIN" },
103  { SR_MQFLAG_AUTORANGE, " AUTO" },
104  { SR_MQFLAG_RELATIVE, " REL" },
105  { SR_MQFLAG_SPL_FREQ_WEIGHT_A, "(A)" },
106  { SR_MQFLAG_SPL_FREQ_WEIGHT_C, "(C)" },
107  { SR_MQFLAG_SPL_FREQ_WEIGHT_Z, "(Z)" },
108  { SR_MQFLAG_SPL_FREQ_WEIGHT_FLAT, "(SPL)" },
109  { SR_MQFLAG_SPL_TIME_WEIGHT_S, " S" },
110  { SR_MQFLAG_SPL_TIME_WEIGHT_F, " F" },
111  { SR_MQFLAG_SPL_LAT, " LAT" },
112  /* Not a standard function for SLMs, so this is a made-up notation. */
113  { SR_MQFLAG_SPL_PCT_OVER_ALARM, "%oA" },
114  { SR_MQFLAG_DURATION, " DURATION" },
115  { SR_MQFLAG_AVG, " AVG" },
116  { SR_MQFLAG_REFERENCE, " REF" },
117  { SR_MQFLAG_UNSTABLE, " UNSTABLE" },
118  { SR_MQFLAG_FOUR_WIRE, " 4-WIRE" },
119  ALL_ZERO
120 };
121 
122 /** @private */
123 SR_PRIV int sr_analog_init(struct sr_datafeed_analog *analog,
124  struct sr_analog_encoding *encoding,
125  struct sr_analog_meaning *meaning,
126  struct sr_analog_spec *spec,
127  int digits)
128 {
129  memset(analog, 0, sizeof(*analog));
130  memset(encoding, 0, sizeof(*encoding));
131  memset(meaning, 0, sizeof(*meaning));
132  memset(spec, 0, sizeof(*spec));
133 
134  analog->encoding = encoding;
135  analog->meaning = meaning;
136  analog->spec = spec;
137 
138  encoding->unitsize = sizeof(float);
139  encoding->is_float = TRUE;
140 #ifdef WORDS_BIGENDIAN
141  encoding->is_bigendian = TRUE;
142 #else
143  encoding->is_bigendian = FALSE;
144 #endif
145  encoding->digits = digits;
146  encoding->is_digits_decimal = TRUE;
147  encoding->scale.p = 1;
148  encoding->scale.q = 1;
149  encoding->offset.p = 0;
150  encoding->offset.q = 1;
151 
152  spec->spec_digits = digits;
153 
154  return SR_OK;
155 }
156 
157 /**
158  * Convert an analog datafeed payload to an array of floats.
159  *
160  * Sufficient memory for outbuf must have been pre-allocated by the caller,
161  * who is also responsible for freeing it when no longer needed.
162  *
163  * @param[in] analog The analog payload to convert. Must not be NULL.
164  * analog->data, analog->meaning, and analog->encoding
165  * must not be NULL.
166  * @param[out] outbuf Memory where to store the result. Must not be NULL.
167  *
168  * @retval SR_OK Success.
169  * @retval SR_ERR Unsupported encoding.
170  * @retval SR_ERR_ARG Invalid argument.
171  *
172  * @since 0.4.0
173  */
175  float *outbuf)
176 {
177  unsigned int b, count;
178  gboolean bigendian;
179 
180  if (!analog || !(analog->data) || !(analog->meaning)
181  || !(analog->encoding) || !outbuf)
182  return SR_ERR_ARG;
183 
184  count = analog->num_samples * g_slist_length(analog->meaning->channels);
185 
186 #ifdef WORDS_BIGENDIAN
187  bigendian = TRUE;
188 #else
189  bigendian = FALSE;
190 #endif
191 
192  if (!analog->encoding->is_float) {
193  float offset = analog->encoding->offset.p / (float)analog->encoding->offset.q;
194  float scale = analog->encoding->scale.p / (float)analog->encoding->scale.q;
195  gboolean is_signed = analog->encoding->is_signed;
196  gboolean is_bigendian = analog->encoding->is_bigendian;
197  int8_t *data8 = (int8_t *)(analog->data);
198  int16_t *data16 = (int16_t *)(analog->data);
199  int32_t *data32 = (int32_t *)(analog->data);
200 
201  switch (analog->encoding->unitsize) {
202  case 1:
203  if (is_signed) {
204  for (unsigned int i = 0; i < count; i++) {
205  outbuf[i] = scale * data8[i];
206  outbuf[i] += offset;
207  }
208  } else {
209  for (unsigned int i = 0; i < count; i++) {
210  outbuf[i] = scale * R8(data8 + i);
211  outbuf[i] += offset;
212  }
213  }
214  break;
215  case 2:
216  if (is_signed && is_bigendian) {
217  for (unsigned int i = 0; i < count; i++) {
218  outbuf[i] = scale * RB16S(&data16[i]);
219  outbuf[i] += offset;
220  }
221  } else if (is_bigendian) {
222  for (unsigned int i = 0; i < count; i++) {
223  outbuf[i] = scale * RB16(&data16[i]);
224  outbuf[i] += offset;
225  }
226  } else if (is_signed) {
227  for (unsigned int i = 0; i < count; i++) {
228  outbuf[i] = scale * RL16S(&data16[i]);
229  outbuf[i] += offset;
230  }
231  } else {
232  for (unsigned int i = 0; i < count; i++) {
233  outbuf[i] = scale * RL16(&data16[i]);
234  outbuf[i] += offset;
235  }
236  }
237  break;
238  case 4:
239  if (is_signed && is_bigendian) {
240  for (unsigned int i = 0; i < count; i++) {
241  outbuf[i] = scale * RB32S(&data32[i]);
242  outbuf[i] += offset;
243  }
244  } else if (is_bigendian) {
245  for (unsigned int i = 0; i < count; i++) {
246  outbuf[i] = scale * RB32(&data32[i]);
247  outbuf[i] += offset;
248  }
249  } else if (is_signed) {
250  for (unsigned int i = 0; i < count; i++) {
251  outbuf[i] = scale * RL32S(&data32[i]);
252  outbuf[i] += offset;
253  }
254  } else {
255  for (unsigned int i = 0; i < count; i++) {
256  outbuf[i] = scale * RL32(&data32[i]);
257  outbuf[i] += offset;
258  }
259  }
260  break;
261  default:
262  sr_err("Unsupported unit size '%d' for analog-to-float"
263  " conversion.", analog->encoding->unitsize);
264  return SR_ERR;
265  }
266  return SR_OK;
267  }
268 
269  if (analog->encoding->unitsize == sizeof(float)
270  && analog->encoding->is_bigendian == bigendian
271  && analog->encoding->scale.p == 1
272  && analog->encoding->scale.q == 1
273  && analog->encoding->offset.p / (float)analog->encoding->offset.q == 0) {
274  /* The data is already in the right format. */
275  memcpy(outbuf, analog->data, count * sizeof(float));
276  } else {
277  for (unsigned int i = 0; i < count; i += analog->encoding->unitsize) {
278  for (b = 0; b < analog->encoding->unitsize; b++) {
279  if (analog->encoding->is_bigendian == bigendian)
280  ((uint8_t *)outbuf)[i + b] =
281  ((uint8_t *)analog->data)[i * analog->encoding->unitsize + b];
282  else
283  ((uint8_t *)outbuf)[i + (analog->encoding->unitsize - b)] =
284  ((uint8_t *)analog->data)[i * analog->encoding->unitsize + b];
285  }
286  if (analog->encoding->scale.p != 1
287  || analog->encoding->scale.q != 1)
288  outbuf[i] = (outbuf[i] * analog->encoding->scale.p) / analog->encoding->scale.q;
289  float offset = ((float)analog->encoding->offset.p / (float)analog->encoding->offset.q);
290  outbuf[i] += offset;
291  }
292  }
293 
294  return SR_OK;
295 }
296 
297 /**
298  * Scale a float value to the appropriate SI prefix.
299  *
300  * @param[in,out] value The float value to convert to appropriate SI prefix.
301  * @param[in,out] digits The number of significant decimal digits in value.
302  *
303  * @return The SI prefix to which value was scaled, as a printable string.
304  *
305  * @since 0.5.0
306  */
307 SR_API const char *sr_analog_si_prefix(float *value, int *digits)
308 {
309 /** @cond PRIVATE */
310 #define NEG_PREFIX_COUNT 5 /* number of prefixes below unity */
311 #define POS_PREFIX_COUNT (int)(ARRAY_SIZE(prefixes) - NEG_PREFIX_COUNT - 1)
312 /** @endcond */
313  static const char *prefixes[] = { "f", "p", "n", "µ", "m", "", "k", "M", "G", "T" };
314 
315  if (!value || !digits || isnan(*value))
316  return prefixes[NEG_PREFIX_COUNT];
317 
318  float logval = log10f(fabsf(*value));
319  int prefix = (logval / 3) - (logval < 1);
320 
321  if (prefix < -NEG_PREFIX_COUNT)
322  prefix = -NEG_PREFIX_COUNT;
323  if (3 * prefix < -*digits)
324  prefix = (-*digits + 2 * (*digits < 0)) / 3;
325  if (prefix > POS_PREFIX_COUNT)
326  prefix = POS_PREFIX_COUNT;
327 
328  *value *= powf(10, -3 * prefix);
329  *digits += 3 * prefix;
330 
331  return prefixes[prefix + NEG_PREFIX_COUNT];
332 }
333 
334 /**
335  * Check if a unit "accepts" an SI prefix.
336  *
337  * E.g. SR_UNIT_VOLT is SI prefix friendly while SR_UNIT_DECIBEL_MW or
338  * SR_UNIT_PERCENTAGE are not.
339  *
340  * @param[in] unit The unit to check for SI prefix "friendliness".
341  *
342  * @return TRUE if the unit "accept" an SI prefix.
343  *
344  * @since 0.5.0
345  */
347 {
348  static const enum sr_unit prefix_friendly_units[] = {
349  SR_UNIT_VOLT,
351  SR_UNIT_OHM,
358  SR_UNIT_WATT,
363  };
364  unsigned int i;
365 
366  for (i = 0; i < ARRAY_SIZE(prefix_friendly_units); i++)
367  if (unit == prefix_friendly_units[i])
368  return TRUE;
369 
370  return FALSE;
371 }
372 
373 /**
374  * Convert the unit/MQ/MQ flags in the analog struct to a string.
375  *
376  * The string is allocated by the function and must be freed by the caller
377  * after use by calling g_free().
378  *
379  * @param[in] analog Struct containing the unit, MQ and MQ flags.
380  * Must not be NULL. analog->meaning must not be NULL.
381  * @param[out] result Pointer to store result. Must not be NULL.
382  *
383  * @retval SR_OK Success.
384  * @retval SR_ERR_ARG Invalid argument.
385  *
386  * @since 0.4.0
387  */
389  char **result)
390 {
391  int i;
392  GString *buf;
393 
394  if (!analog || !(analog->meaning) || !result)
395  return SR_ERR_ARG;
396 
397  buf = g_string_new(NULL);
398 
399  for (i = 0; unit_strings[i].value; i++) {
400  if (analog->meaning->unit == unit_strings[i].value) {
401  g_string_assign(buf, unit_strings[i].str);
402  break;
403  }
404  }
405 
406  /* More than one MQ flag may apply. */
407  for (i = 0; mq_strings[i].value; i++)
408  if (analog->meaning->mqflags & mq_strings[i].value)
409  g_string_append(buf, mq_strings[i].str);
410 
411  *result = buf->str;
412  g_string_free(buf, FALSE);
413 
414  return SR_OK;
415 }
416 
417 /**
418  * Set sr_rational r to the given value.
419  *
420  * @param[out] r Rational number struct to set. Must not be NULL.
421  * @param[in] p Numerator.
422  * @param[in] q Denominator.
423  *
424  * @since 0.4.0
425  */
426 SR_API void sr_rational_set(struct sr_rational *r, int64_t p, uint64_t q)
427 {
428  if (!r)
429  return;
430 
431  r->p = p;
432  r->q = q;
433 }
434 
435 #ifndef HAVE___INT128_T
436 struct sr_int128_t {
437  int64_t high;
438  uint64_t low;
439 };
440 
441 struct sr_uint128_t {
442  uint64_t high;
443  uint64_t low;
444 };
445 
446 static void mult_int64(struct sr_int128_t *res, const int64_t a,
447  const int64_t b)
448 {
449  uint64_t t1, t2, t3, t4;
450 
451  t1 = (UINT32_MAX & a) * (UINT32_MAX & b);
452  t2 = (UINT32_MAX & a) * (b >> 32);
453  t3 = (a >> 32) * (UINT32_MAX & b);
454  t4 = (a >> 32) * (b >> 32);
455 
456  res->low = t1 + (t2 << 32) + (t3 << 32);
457  res->high = (t1 >> 32) + (uint64_t)((uint32_t)(t2)) + (uint64_t)((uint32_t)(t3));
458  res->high >>= 32;
459  res->high += ((int64_t)t2 >> 32) + ((int64_t)t3 >> 32) + t4;
460 }
461 
462 static void mult_uint64(struct sr_uint128_t *res, const uint64_t a,
463  const uint64_t b)
464 {
465  uint64_t t1, t2, t3, t4;
466 
467  // (x1 + x2) * (y1 + y2) = x1*y1 + x1*y2 + x2*y1 + x2*y2
468  t1 = (UINT32_MAX & a) * (UINT32_MAX & b);
469  t2 = (UINT32_MAX & a) * (b >> 32);
470  t3 = (a >> 32) * (UINT32_MAX & b);
471  t4 = (a >> 32) * (b >> 32);
472 
473  res->low = t1 + (t2 << 32) + (t3 << 32);
474  res->high = (t1 >> 32) + (uint64_t)((uint32_t)(t2)) + (uint64_t)((uint32_t)(t3));
475  res->high >>= 32;
476  res->high += ((int64_t)t2 >> 32) + ((int64_t)t3 >> 32) + t4;
477 }
478 #endif
479 
480 /**
481  * Compare two sr_rational for equality.
482  *
483  * The values are compared for numerical equality, i.e. 2/10 == 1/5.
484  *
485  * @param[in] a First value.
486  * @param[in] b Second value.
487  *
488  * @retval 1 if both values are equal.
489  * @retval 0 Otherwise.
490  *
491  * @since 0.5.0
492  */
493 SR_API int sr_rational_eq(const struct sr_rational *a, const struct sr_rational *b)
494 {
495 #ifdef HAVE___INT128_T
496  __int128_t m1, m2;
497 
498  /* p1/q1 = p2/q2 <=> p1*q2 = p2*q1 */
499  m1 = ((__int128_t)(b->p)) * ((__uint128_t)a->q);
500  m2 = ((__int128_t)(a->p)) * ((__uint128_t)b->q);
501 
502  return (m1 == m2);
503 
504 #else
505  struct sr_int128_t m1, m2;
506 
507  mult_int64(&m1, a->q, b->p);
508  mult_int64(&m2, a->p, b->q);
509 
510  return (m1.high == m2.high) && (m1.low == m2.low);
511 #endif
512 }
513 
514 /**
515  * Multiply two sr_rational.
516  *
517  * The resulting nominator/denominator are reduced if the result would not fit
518  * otherwise. If the resulting nominator/denominator are relatively prime,
519  * this may not be possible.
520  *
521  * It is safe to use the same variable for result and input values.
522  *
523  * @param[in] a First value.
524  * @param[in] b Second value.
525  * @param[out] res Result.
526  *
527  * @retval SR_OK Success.
528  * @retval SR_ERR_ARG Resulting value too large.
529  *
530  * @since 0.5.0
531  */
532 SR_API int sr_rational_mult(struct sr_rational *res, const struct sr_rational *a,
533  const struct sr_rational *b)
534 {
535 #ifdef HAVE___INT128_T
536  __int128_t p;
537  __uint128_t q;
538 
539  p = (__int128_t)(a->p) * (__int128_t)(b->p);
540  q = (__uint128_t)(a->q) * (__uint128_t)(b->q);
541 
542  if ((p > INT64_MAX) || (p < INT64_MIN) || (q > UINT64_MAX)) {
543  while (!((p & 1) || (q & 1))) {
544  p /= 2;
545  q /= 2;
546  }
547  }
548 
549  if ((p > INT64_MAX) || (p < INT64_MIN) || (q > UINT64_MAX)) {
550  // TODO: determine gcd to do further reduction
551  return SR_ERR_ARG;
552  }
553 
554  res->p = (int64_t)p;
555  res->q = (uint64_t)q;
556 
557  return SR_OK;
558 
559 #else
560  struct sr_int128_t p;
561  struct sr_uint128_t q;
562 
563  mult_int64(&p, a->p, b->p);
564  mult_uint64(&q, a->q, b->q);
565 
566  while (!(p.low & 1) && !(q.low & 1)) {
567  p.low /= 2;
568  if (p.high & 1)
569  p.low |= (1ll << 63);
570  p.high >>= 1;
571  q.low /= 2;
572  if (q.high & 1)
573  q.low |= (1ll << 63);
574  q.high >>= 1;
575  }
576 
577  if (q.high)
578  return SR_ERR_ARG;
579  if ((p.high >= 0) && (p.low > INT64_MAX))
580  return SR_ERR_ARG;
581  if (p.high < -1)
582  return SR_ERR_ARG;
583 
584  res->p = (int64_t)p.low;
585  res->q = q.low;
586 
587  return SR_OK;
588 #endif
589 }
590 
591 /**
592  * Divide rational a by rational b.
593  *
594  * The resulting nominator/denominator are reduced if the result would not fit
595  * otherwise. If the resulting nominator/denominator are relatively prime,
596  * this may not be possible.
597  *
598  * It is safe to use the same variable for result and input values.
599  *
600  * @param[in] num Numerator.
601  * @param[in] div Divisor.
602  * @param[out] res Result.
603  *
604  * @retval SR_OK Success.
605  * @retval SR_ERR_ARG Division by zero.
606  * @retval SR_ERR_ARG Denominator of divisor too large.
607  * @retval SR_ERR_ARG Resulting value too large.
608  *
609  * @since 0.5.0
610  */
611 SR_API int sr_rational_div(struct sr_rational *res, const struct sr_rational *num,
612  const struct sr_rational *div)
613 {
614  struct sr_rational t;
615 
616  if (div->q > INT64_MAX)
617  return SR_ERR_ARG;
618  if (div->p == 0)
619  return SR_ERR_ARG;
620 
621  if (div->p > 0) {
622  t.p = div->q;
623  t.q = div->p;
624  } else {
625  t.p = -div->q;
626  t.q = -div->p;
627  }
628 
629  return sr_rational_mult(res, num, &t);
630 }
631 
632 /** @} */
Generic/unspecified error.
Definition: libsigrok.h:68
Time is duration (as opposed to epoch, ...).
Definition: libsigrok.h:379
Reference value shown.
Definition: libsigrok.h:383
Sound pressure level is not weighted in the frequency domain, albeit without standards-defined low an...
Definition: libsigrok.h:365
int sr_rational_mult(struct sr_rational *res, const struct sr_rational *a, const struct sr_rational *b)
Multiply two sr_rational.
Definition: analog.c:532
void sr_rational_set(struct sr_rational *r, int64_t p, uint64_t q)
Set sr_rational r to the given value.
Definition: analog.c:426
Sound pressure level is A-weighted in the frequency domain, according to IEC 61672:2003.
Definition: libsigrok.h:356
Measurement is four wire (e.g.
Definition: libsigrok.h:387
Degrees Fahrenheit (temperature).
Definition: libsigrok.h:255
This is a true RMS measurement.
Definition: libsigrok.h:341
Normalized (0 to 1) concentration of a substance or compound with 0 representing a concentration of 0...
Definition: libsigrok.h:286
Plane angle in 1/360th of a full circle.
Definition: libsigrok.h:302
Percent value.
Definition: libsigrok.h:259
Sound pressure level measurement is S-weighted (1s) in the time domain.
Definition: libsigrok.h:368
Ampere (current).
Definition: libsigrok.h:245
Unit of conductance, the inverse of resistance.
Definition: libsigrok.h:265
Sound pressure level measurement is F-weighted (125ms) in the time domain.
Definition: libsigrok.h:371
No error.
Definition: libsigrok.h:67
Degrees Celsius (temperature).
Definition: libsigrok.h:253
GSList * channels
Definition: libsigrok.h:528
Mass in pound [lb].
Definition: libsigrok.h:314
gboolean is_signed
Definition: libsigrok.h:510
Mass in momme.
Definition: libsigrok.h:322
The public libsigrok header file to be used by frontends.
An absolute measurement of power, in decibels, referenced to 1 milliwatt (dBm).
Definition: libsigrok.h:270
Sound pressure level is time-averaged (LAT), also known as Equivalent Continuous A-weighted Sound Lev...
Definition: libsigrok.h:374
Device is in autoranging mode.
Definition: libsigrok.h:351
Volt.
Definition: libsigrok.h:243
Pieces (number of items).
Definition: libsigrok.h:326
Sound pressure level is C-weighted in the frequency domain, according to IEC 61672:2003.
Definition: libsigrok.h:359
struct sr_rational scale
Definition: libsigrok.h:520
Mass in tael (variants: Hong Kong, Singapore/Malaysia, Taiwan)
Definition: libsigrok.h:320
struct sr_analog_encoding * encoding
Definition: libsigrok.h:503
Device is in "min" mode, only updating upon a new min value.
Definition: libsigrok.h:349
Consumption [Wh].
Definition: libsigrok.h:294
Sound pressure level represented as a percentage of measurements that were over a preset alarm level...
Definition: libsigrok.h:377
Mass in tola.
Definition: libsigrok.h:324
Voltage measurement is alternating current (AC).
Definition: libsigrok.h:337
Farad (capacity).
Definition: libsigrok.h:249
int sr_analog_unit_to_string(const struct sr_datafeed_analog *analog, char **result)
Convert the unit/MQ/MQ flags in the analog struct to a string.
Definition: analog.c:388
Device is in "hold" mode (repeating the last measurement).
Definition: libsigrok.h:345
int8_t spec_digits
Number of significant digits after the decimal point if positive, or number of non-significant digits...
Definition: libsigrok.h:538
enum sr_unit unit
Definition: libsigrok.h:526
Ohm (resistance).
Definition: libsigrok.h:247
int sr_analog_to_float(const struct sr_datafeed_analog *analog, float *outbuf)
Convert an analog datafeed payload to an array of floats.
Definition: analog.c:174
sr_unit
Unit of measured quantity, sr_analog_meaning.unit.
Definition: libsigrok.h:241
struct sr_analog_meaning * meaning
Definition: libsigrok.h:504
Hertz (frequency, 1/s, [Hz]).
Definition: libsigrok.h:257
Boolean value.
Definition: libsigrok.h:261
Kelvin (temperature).
Definition: libsigrok.h:251
#define SR_PRIV
Definition: libsigrok.h:128
Mass in carat [ct].
Definition: libsigrok.h:308
gboolean is_digits_decimal
Definition: libsigrok.h:519
Device is in "avg" mode, averaging upon each new value.
Definition: libsigrok.h:381
Voltage measurement is direct current (DC).
Definition: libsigrok.h:339
Pressure in hectopascal.
Definition: libsigrok.h:298
struct sr_analog_spec * spec
Definition: libsigrok.h:505
uint64_t q
Denominator of the rational number.
Definition: libsigrok.h:472
Revolutions per minute.
Definition: libsigrok.h:288
Mass in troy ounce [oz t].
Definition: libsigrok.h:312
Apparent power [VA].
Definition: libsigrok.h:290
Mass in grain [gr].
Definition: libsigrok.h:318
Henry (inductance).
Definition: libsigrok.h:304
gboolean sr_analog_si_prefix_friendly(enum sr_unit unit)
Check if a unit "accepts" an SI prefix.
Definition: analog.c:346
int64_t p
Numerator of the rational number.
Definition: libsigrok.h:470
Voltage in decibel, referenced to 1 volt (dBV).
Definition: libsigrok.h:272
Analog datafeed payload for type SR_DF_ANALOG.
Definition: libsigrok.h:500
Function argument error.
Definition: libsigrok.h:70
struct sr_rational offset
Definition: libsigrok.h:521
const char * sr_analog_si_prefix(float *value, int *digits)
Scale a float value to the appropriate SI prefix.
Definition: analog.c:307
Sound pressure level is Z-weighted (i.e.
Definition: libsigrok.h:362
Real power [W].
Definition: libsigrok.h:292
enum sr_mqflag mqflags
Definition: libsigrok.h:527
Relative humidity assuming air temperature of 293 Kelvin (rF).
Definition: libsigrok.h:300
Value is voltage drop across a diode, or NAN.
Definition: libsigrok.h:343
Sound pressure level, in decibels, relative to 20 micropascals.
Definition: libsigrok.h:280
Mass in pennyweight [dwt].
Definition: libsigrok.h:316
Device is in "max" mode, only updating upon a new max value.
Definition: libsigrok.h:347
Device is in relative mode.
Definition: libsigrok.h:353
uint32_t num_samples
Definition: libsigrok.h:502
int sr_rational_eq(const struct sr_rational *a, const struct sr_rational *b)
Compare two sr_rational for equality.
Definition: analog.c:493
Time in seconds.
Definition: libsigrok.h:263
gboolean is_float
Definition: libsigrok.h:511
Wind speed in meters per second.
Definition: libsigrok.h:296
gboolean is_bigendian
Definition: libsigrok.h:512
int sr_rational_div(struct sr_rational *res, const struct sr_rational *num, const struct sr_rational *div)
Divide rational a by rational b.
Definition: analog.c:611
int8_t digits
Number of significant digits after the decimal point if positive, or number of non-significant digits...
Definition: libsigrok.h:518
Mass in ounce [oz].
Definition: libsigrok.h:310
Measurements that intrinsically do not have units attached, such as ratios, gains, etc.
Definition: libsigrok.h:278
#define SR_API
Definition: libsigrok.h:121
Unstable value (hasn't settled yet).
Definition: libsigrok.h:385
Mass in gram [g].
Definition: libsigrok.h:306