libsigrok  0.5.0
sigrok hardware access and backend library
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
Functions
Analog data handling

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...
 

Detailed Description

Handling and converting analog data.

Function Documentation

const char* sr_analog_si_prefix ( float *  value,
int *  digits 
)

Scale a float value to the appropriate SI prefix.

Parameters
[in,out]valueThe float value to convert to appropriate SI prefix.
[in,out]digitsThe number of significant decimal digits in value.
Returns
The SI prefix to which value was scaled, as a printable string.
Since
0.5.0

Definition at line 308 of file analog.c.

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.

Parameters
[in]unitThe unit to check for SI prefix "friendliness".
Returns
TRUE if the unit "accept" an SI prefix.
Since
0.5.0

Definition at line 347 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.

Sufficient memory for outbuf must have been pre-allocated by the caller, who is also responsible for freeing it when no longer needed.

Parameters
[in]analogThe analog payload to convert. Must not be NULL. analog->data, analog->meaning, and analog->encoding must not be NULL.
[out]outbufMemory where to store the result. Must not be NULL.
Return values
SR_OKSuccess.
SR_ERRUnsupported encoding.
SR_ERR_ARGInvalid argument.
Since
0.4.0

Definition at line 174 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.

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().

Parameters
[in]analogStruct containing the unit, MQ and MQ flags. Must not be NULL. analog->meaning must not be NULL.
[out]resultPointer to store result. Must not be NULL.
Return values
SR_OKSuccess.
SR_ERR_ARGInvalid argument.
Since
0.4.0

Definition at line 392 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.

Parameters
[in]numNumerator.
[in]divDivisor.
[out]resResult.
Return values
SR_OKSuccess.
SR_ERR_ARGDivision by zero.
SR_ERR_ARGDenominator of divisor too large.
SR_ERR_ARGResulting value too large.
Since
0.5.0

Definition at line 615 of file analog.c.

References sr_rational::p, sr_rational::q, SR_ERR_ARG, and sr_rational_mult().

+ Here is the call graph for this function:

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.

Parameters
[in]aFirst value.
[in]bSecond value.
Return values
1if both values are equal.
0Otherwise.
Since
0.5.0

Definition at line 497 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.

Parameters
[in]aFirst value.
[in]bSecond value.
[out]resResult.
Return values
SR_OKSuccess.
SR_ERR_ARGResulting value too large.
Since
0.5.0

Definition at line 536 of file analog.c.

References sr_rational::p, sr_rational::q, SR_ERR_ARG, and SR_OK.

Referenced by sr_rational_div().

+ Here is the caller graph for this function:

void sr_rational_set ( struct sr_rational r,
int64_t  p,
uint64_t  q 
)

Set sr_rational r to the given value.

Parameters
[out]rRational number struct to set. Must not be NULL.
[in]pNumerator.
[in]qDenominator.
Since
0.4.0

Definition at line 430 of file analog.c.

References sr_rational::p, and sr_rational::q.