libsigrok
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros
Functions
strutil.c File Reference
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include "sigrok.h"
#include "sigrok-internal.h"
Include dependency graph for strutil.c:

Go to the source code of this file.

Functions

SR_API char * sr_samplerate_string (uint64_t samplerate)
 Convert a numeric samplerate value to its "natural" string representation. More...
 
SR_API char * sr_period_string (uint64_t frequency)
 Convert a numeric frequency value to the "natural" string representation of its period. More...
 
SR_API char ** sr_parse_triggerstring (struct sr_dev *dev, const char *triggerstring)
 Parse a trigger specification string. More...
 
SR_API int sr_parse_sizestring (const char *sizestring, uint64_t *size)
 Convert a "natural" string representation of a size value to uint64_t. More...
 
SR_API uint64_t sr_parse_timestring (const char *timestring)
 Convert a "natural" string representation of a time value to an uint64_t value in milliseconds. More...
 
SR_API gboolean sr_parse_boolstring (const char *boolstr)
 

Function Documentation

SR_API gboolean sr_parse_boolstring ( const char *  boolstr)

Definition at line 304 of file strutil.c.

SR_API int sr_parse_sizestring ( const char *  sizestring,
uint64_t *  size 
)

Convert a "natural" string representation of a size value to uint64_t.

E.g. a value of "3k" or "3 K" would be converted to 3000, a value of "15M" would be converted to 15000000.

Value representations other than decimal (such as hex or octal) are not supported. Only 'k' (kilo), 'm' (mega), 'g' (giga) suffixes are supported. Spaces (but not other whitespace) between value and suffix are allowed.

Parameters
sizestringA string containing a (decimal) size value.
sizePointer to uint64_t which will contain the string's size value.
Returns
SR_OK upon success, SR_ERR upon errors.

Definition at line 223 of file strutil.c.

References SR_ERR, SR_GHZ, SR_KHZ, SR_MHZ, and SR_OK.

Referenced by sr_session_load().

SR_API uint64_t sr_parse_timestring ( const char *  timestring)

Convert a "natural" string representation of a time value to an uint64_t value in milliseconds.

E.g. a value of "3s" or "3 s" would be converted to 3000, a value of "15ms" would be converted to 15.

Value representations other than decimal (such as hex or octal) are not supported. Only lower-case "s" and "ms" time suffixes are supported. Spaces (but not other whitespace) between value and suffix are allowed.

Parameters
timestringA string containing a (decimal) time value.
Returns
The string's time value as uint64_t, in milliseconds.

TODO: Error handling. TODO: Add support for "m" (minutes) and others. TODO: picoseconds? TODO: Allow both lower-case and upper-case.

Definition at line 281 of file strutil.c.

SR_API char** sr_parse_triggerstring ( struct sr_dev dev,
const char *  triggerstring 
)

Parse a trigger specification string.

Parameters
devThe device for which the trigger specification is intended.
triggerstringThe string containing the trigger specification for one or more probes of this device. Entries for multiple probes are comma-separated. Triggers are specified in the form key=value, where the key is a probe number (or probe name) and the value is the requested trigger type. Valid trigger types currently include 'r' (rising edge), 'f' (falling edge), 'c' (any pin value change), '0' (low value), or '1' (high value). Example: "1=r,sck=f,miso=0,7=c"
Returns
Pointer to a list of trigger types (strings), or NULL upon errors. The pointer list (if non-NULL) has as many entries as the respective device has probes (all physically available probes, not just enabled ones). Entries of the list which don't have a trigger value set in 'triggerstring' are NULL, the other entries contain the respective trigger type which is requested for the respective probe (e.g. "r", "c", and so on).

Definition at line 134 of file strutil.c.

References sr_dev_driver::dev_info_get, sr_dev::driver, sr_probe::enabled, sr_probe::index, sr_probe::name, sr_dev::probes, SR_DI_TRIGGER_TYPES, sr_err(), and sr_probe::trigger.

Here is the call graph for this function:

SR_API char* sr_period_string ( uint64_t  frequency)

Convert a numeric frequency value to the "natural" string representation of its period.

E.g. a value of 3000000 would be converted to "3 us", 20000 to "50 ms".

Parameters
frequencyThe frequency in Hz.
Returns
A g_try_malloc()ed string representation of the frequency value, or NULL upon errors. The caller is responsible to g_free() the memory.

Definition at line 84 of file strutil.c.

References sr_err(), SR_GHZ, SR_KHZ, and SR_MHZ.

Here is the call graph for this function:

SR_API char* sr_samplerate_string ( uint64_t  samplerate)

Convert a numeric samplerate value to its "natural" string representation.

E.g. a value of 3000000 would be converted to "3 MHz", 20000 to "20 kHz", 31500 would become "31.5 kHz".

Parameters
samplerateThe samplerate in Hz.
Returns
A g_try_malloc()ed string representation of the samplerate value, or NULL upon errors. The caller is responsible to g_free() the memory.

Definition at line 39 of file strutil.c.

References sr_err(), SR_GHZ, SR_KHZ, and SR_MHZ.

Referenced by init(), and sr_session_save().

Here is the call graph for this function: