libsigrok
unreleased development snapshot
sigrok hardware access and backend library
|
Handling and converting analog data. More...
Functions | |
int | sr_analog_to_float (const struct sr_datafeed_analog *analog, float *outbuf) |
Convert an analog datafeed payload to an array of floats. More... | |
const char * | sr_analog_si_prefix (float *value, int *digits) |
Scale a float value to the appropriate SI prefix. More... | |
gboolean | sr_analog_si_prefix_friendly (enum sr_unit unit) |
Check if a unit "accepts" an SI prefix. More... | |
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. More... | |
void | sr_rational_set (struct sr_rational *r, int64_t p, uint64_t q) |
Set sr_rational r to the given value. More... | |
int | sr_rational_eq (const struct sr_rational *a, const struct sr_rational *b) |
Compare two sr_rational for equality. More... | |
int | sr_rational_mult (struct sr_rational *res, const struct sr_rational *a, const struct sr_rational *b) |
Multiply two sr_rational. More... | |
int | sr_rational_div (struct sr_rational *res, const struct sr_rational *num, const struct sr_rational *div) |
Divide rational a by rational b. More... | |
Handling and converting analog data.
const char* sr_analog_si_prefix | ( | float * | value, |
int * | digits | ||
) |
Scale a float value to the appropriate SI prefix.
[in,out] | value | The float value to convert to appropriate SI prefix. |
[in,out] | digits | The number of significant decimal digits in value. |
gboolean sr_analog_si_prefix_friendly | ( | enum sr_unit | unit | ) |
Check if a unit "accepts" an SI prefix.
E.g. SR_UNIT_VOLT is SI prefix friendly while SR_UNIT_DECIBEL_MW or SR_UNIT_PERCENTAGE are not.
[in] | unit | The unit to check for SI prefix "friendliness". |
Definition at line 430 of file analog.c.
References SR_UNIT_AMPERE, SR_UNIT_FARAD, SR_UNIT_GRAM, SR_UNIT_HENRY, SR_UNIT_HERTZ, SR_UNIT_KELVIN, SR_UNIT_METER_SECOND, SR_UNIT_OHM, SR_UNIT_SECOND, SR_UNIT_SIEMENS, SR_UNIT_VOLT, SR_UNIT_VOLT_AMPERE, SR_UNIT_WATT, and SR_UNIT_WATT_HOUR.
int sr_analog_to_float | ( | const struct sr_datafeed_analog * | analog, |
float * | outbuf | ||
) |
Convert an analog datafeed payload to an array of floats.
The caller must provide the #outbuf space for the conversion result, and is expected to free allocated space after use.
[in] | analog | The analog payload to convert. Must not be NULL. analog->data, analog->meaning, and analog->encoding must not be NULL. |
[out] | outbuf | Memory where to store the result. Must not be NULL. |
SR_OK | Success. |
SR_ERR | Unsupported encoding. |
SR_ERR_ARG | Invalid argument. |
Definition at line 177 of file analog.c.
References sr_analog_meaning::channels, sr_datafeed_analog::data, sr_datafeed_analog::encoding, sr_analog_encoding::is_bigendian, sr_analog_encoding::is_float, sr_analog_encoding::is_signed, sr_datafeed_analog::meaning, sr_datafeed_analog::num_samples, sr_analog_encoding::offset, sr_rational::p, sr_rational::q, sr_analog_encoding::scale, SR_ERR, SR_ERR_ARG, SR_OK, and sr_analog_encoding::unitsize.
Referenced by sr_a2l_schmitt_trigger(), and sr_a2l_threshold().
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.
The string is allocated by the function and must be freed by the caller after use by calling g_free().
[in] | analog | Struct containing the unit, MQ and MQ flags. Must not be NULL. analog->meaning must not be NULL. |
[out] | result | Pointer to store result. Must not be NULL. |
SR_OK | Success. |
SR_ERR_ARG | Invalid argument. |
Definition at line 472 of file analog.c.
References sr_datafeed_analog::meaning, sr_analog_meaning::mqflags, SR_ERR_ARG, SR_OK, and sr_analog_meaning::unit.
int sr_rational_div | ( | struct sr_rational * | res, |
const struct sr_rational * | num, | ||
const struct sr_rational * | div | ||
) |
Divide rational a by rational b.
The resulting nominator/denominator are reduced if the result would not fit otherwise. If the resulting nominator/denominator are relatively prime, this may not be possible.
It is safe to use the same variable for result and input values.
[in] | num | Numerator. |
[in] | div | Divisor. |
[out] | res | Result. |
SR_OK | Success. |
SR_ERR_ARG | Division by zero, denominator of divisor too large, or resulting value too large. |
Definition at line 693 of file analog.c.
References sr_rational::p, sr_rational::q, SR_ERR_ARG, and sr_rational_mult().
int sr_rational_eq | ( | const struct sr_rational * | a, |
const struct sr_rational * | b | ||
) |
Compare two sr_rational for equality.
The values are compared for numerical equality, i.e. 2/10 == 1/5.
[in] | a | First value. |
[in] | b | Second value. |
1 | if both values are equal. |
0 | Otherwise. |
Definition at line 576 of file analog.c.
References sr_rational::p, and sr_rational::q.
int sr_rational_mult | ( | struct sr_rational * | res, |
const struct sr_rational * | a, | ||
const struct sr_rational * | b | ||
) |
Multiply two sr_rational.
The resulting nominator/denominator are reduced if the result would not fit otherwise. If the resulting nominator/denominator are relatively prime, this may not be possible.
It is safe to use the same variable for result and input values.
[in] | a | First value. |
[in] | b | Second value. |
[out] | res | Result. |
SR_OK | Success. |
SR_ERR_ARG | Resulting value too large. |
Definition at line 615 of file analog.c.
References sr_rational::p, sr_rational::q, SR_ERR_ARG, and SR_OK.
Referenced by sr_rational_div().
void sr_rational_set | ( | struct sr_rational * | r, |
int64_t | p, | ||
uint64_t | q | ||
) |
Set sr_rational r to the given value.
[out] | r | Rational number struct to set. Must not be NULL. |
[in] | p | Numerator. |
[in] | q | Denominator. |
Definition at line 509 of file analog.c.
References sr_rational::p, and sr_rational::q.