libsigrok  0.3.0
sigrok hardware access and backend library
Functions
String utilities

Helper functions for handling or converting libsigrok-related strings. More...

Functions

char * sr_si_string_u64 (uint64_t x, const char *unit)
 Convert a numeric value value to its "natural" string representation in SI units. More...
 
char * sr_samplerate_string (uint64_t samplerate)
 Convert a numeric samplerate value to its "natural" string representation. More...
 
char * sr_period_string (uint64_t frequency)
 Convert a numeric frequency value to the "natural" string representation of its period. More...
 
char * sr_voltage_string (uint64_t v_p, uint64_t v_q)
 Convert a numeric voltage value to the "natural" string representation of its voltage value. More...
 
char ** sr_parse_triggerstring (const struct sr_dev_inst *sdi, const char *triggerstring)
 Parse a trigger specification string. More...
 
int sr_parse_sizestring (const char *sizestring, uint64_t *size)
 Convert a "natural" string representation of a size value to uint64_t. More...
 
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...
 
gboolean sr_parse_boolstring (const char *boolstr)
 
int sr_parse_period (const char *periodstr, uint64_t *p, uint64_t *q)
 
int sr_parse_voltage (const char *voltstr, uint64_t *p, uint64_t *q)
 

Detailed Description

Helper functions for handling or converting libsigrok-related strings.

Function Documentation

gboolean sr_parse_boolstring ( const char *  boolstr)
Since
0.1.0

Definition at line 572 of file strutil.c.

int sr_parse_period ( const char *  periodstr,
uint64_t *  p,
uint64_t *  q 
)
Since
0.2.0

Definition at line 587 of file strutil.c.

References SR_ERR_ARG, and SR_OK.

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

Definition at line 479 of file strutil.c.

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

Referenced by sr_session_load().

+ Here is the caller graph for this function:

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:

Add support for "m" (minutes) and others.

Add support for picoseconds?

Allow both lower-case and upper-case? If no, document it.

Since
0.1.0

Definition at line 546 of file strutil.c.

char** sr_parse_triggerstring ( const struct sr_dev_inst sdi,
const char *  triggerstring 
)

Parse a trigger specification string.

Parameters
sdiThe device instance for which the trigger specification is intended. Must not be NULL. Also, sdi->driver and sdi->driver->info_get must not be NULL.
triggerstringThe string containing the trigger specification for one or more channels of this device. Entries for multiple channels are comma-separated. Triggers are specified in the form key=value, where the key is a channel number (or channel 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 channels (all physically available channels, 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 channel (e.g. "r", "c", and so on).
Since
0.2.0

Definition at line 391 of file strutil.c.

References sr_dev_inst::channels, sr_dev_driver::config_list, sr_dev_inst::driver, sr_channel::enabled, sr_channel::index, sr_channel::name, SR_CONF_TRIGGER_TYPE, SR_OK, and sr_channel::trigger.

int sr_parse_voltage ( const char *  voltstr,
uint64_t *  p,
uint64_t *  q 
)
Since
0.2.0

Definition at line 620 of file strutil.c.

References SR_ERR_ARG, and SR_OK.

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

Definition at line 295 of file strutil.c.

References SR_GHZ, SR_KHZ, and SR_MHZ.

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

Definition at line 276 of file strutil.c.

References sr_si_string_u64().

Referenced by sr_session_save_init().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

char* sr_si_string_u64 ( uint64_t  x,
const char *  unit 
)

Convert a numeric value value to its "natural" string representation in SI units.

E.g. a value of 3000000, with units set to "W", would be converted to "3 MW", 20000 to "20 kW", 31500 would become "31.5 kW".

Parameters
xThe value to convert.
unitThe unit to append to the string, or NULL if the string has no units.
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.
Since
0.2.0

Definition at line 234 of file strutil.c.

References SR_GHZ, SR_HZ, SR_KHZ, and SR_MHZ.

Referenced by sr_samplerate_string().

+ Here is the caller graph for this function:

char* sr_voltage_string ( uint64_t  v_p,
uint64_t  v_q 
)

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

The voltage is specified as a rational number's numerator and denominator.

E.g. a value of 300000 would be converted to "300mV", 2 to "2V".

Parameters
v_pThe voltage numerator.
v_qThe voltage denominator.
Returns
A g_try_malloc()ed string representation of the voltage value, or NULL upon errors. The caller is responsible to g_free() the memory.
Since
0.2.0

Definition at line 340 of file strutil.c.