25 #include "sigrok-internal.h"
42 uint64_t s = samplerate;
45 o = g_strdup_printf(
"%" PRIu64
" GHz", s /
SR_GHZ(1));
47 o = g_strdup_printf(
"%" PRIu64
".%" PRIu64
" GHz",
50 o = g_strdup_printf(
"%" PRIu64
" MHz", s /
SR_MHZ(1));
52 o = g_strdup_printf(
"%" PRIu64
".%" PRIu64
" MHz",
55 o = g_strdup_printf(
"%" PRIu64
" kHz", s /
SR_KHZ(1));
57 o = g_strdup_printf(
"%" PRIu64
".%" PRIu64
" kHz",
60 o = g_strdup_printf(
"%" PRIu64
" Hz", s);
64 sr_err(
"strutil: %s: Error creating samplerate string.",
90 if (!(o = g_try_malloc0(30 + 1))) {
91 sr_err(
"strutil: %s: o malloc failed", __func__);
95 if (frequency >=
SR_GHZ(1))
96 r = snprintf(o, 30,
"%" PRIu64
" ns", frequency / 1000000000);
97 else if (frequency >=
SR_MHZ(1))
98 r = snprintf(o, 30,
"%" PRIu64
" us", frequency / 1000000);
99 else if (frequency >=
SR_KHZ(1))
100 r = snprintf(o, 30,
"%" PRIu64
" ms", frequency / 1000);
102 r = snprintf(o, 30,
"%" PRIu64
" s", frequency);
135 const char *triggerstring)
139 int max_probes, probenum, i;
140 char **tokens, **triggerlist, *
trigger, *tc, *trigger_types;
143 max_probes = g_slist_length(dev->
probes);
146 if (!(triggerlist = g_try_malloc0(max_probes *
sizeof(
char *)))) {
147 sr_err(
"strutil: %s: triggerlist malloc failed", __func__);
151 tokens = g_strsplit(triggerstring,
",", max_probes);
154 if (!trigger_types) {
155 sr_err(
"strutil: %s: Device doesn't support any triggers.",
160 for (i = 0; tokens[i]; i++) {
161 if (tokens[i][0] <
'0' || tokens[i][0] >
'9') {
164 for (l = dev->
probes; l; l = l->next) {
167 && !strncmp(probe->
name, tokens[i],
168 strlen(probe->
name))) {
169 probenum = probe->
index;
174 probenum = strtol(tokens[i], NULL, 10);
177 if (probenum < 1 || probenum > max_probes) {
178 sr_err(
"strutil: Invalid probe (%d).", probenum);
183 if ((trigger = strchr(tokens[i],
'='))) {
184 for (tc = ++trigger; *tc; tc++) {
185 if (strchr(trigger_types, *tc) == NULL) {
186 sr_err(
"strutil: Unsupported trigger "
193 triggerlist[probenum - 1] = g_strdup(trigger);
199 for (i = 0; i < max_probes; i++)
200 g_free(triggerlist[i]);
225 int multiplier, done;
228 *size = strtoull(sizestring, &s, 10);
231 while (s && *s && multiplier == 0 && !done) {
256 if (*s && strcasecmp(s,
"Hz"))
286 time_msec = strtoull(timestring, &s, 10);
287 if (time_msec == 0 && s == timestring)
295 else if (!strcmp(s,
"ms"))
309 if (!g_strcasecmp(boolstr,
"true") ||
310 !g_strcasecmp(boolstr,
"yes") ||
311 !g_strcasecmp(boolstr,
"on") ||
312 !g_strcasecmp(boolstr,
"1"))
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...
SR_API char ** sr_parse_triggerstring(struct sr_dev *dev, const char *triggerstring)
Parse a trigger specification string.
SR_API char * sr_period_string(uint64_t frequency)
Convert a numeric frequency value to the "natural" string representation of its period.
SR_API char * sr_samplerate_string(uint64_t samplerate)
Convert a numeric samplerate value to its "natural" string representation.
void *(* dev_info_get)(int dev_index, int dev_info_id)
SR_API int sr_parse_sizestring(const char *sizestring, uint64_t *size)
Convert a "natural" string representation of a size value to uint64_t.
SR_API gboolean sr_parse_boolstring(const char *boolstring)
struct sr_dev_driver * driver
SR_PRIV int sr_err(const char *format,...)