X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=src%2Finput%2Fcsv.c;h=3a42fc9b1e6cfd1d479bb7f9de72643f862e759f;hb=4c5ac0cf5b3e8a13d6f0ff4255fa21ed6874774a;hp=af04ae212d482ecad2cec200685ca866141e8408;hpb=307b23939094db63535226d12ef175725cf5e623;p=libsigrok.git diff --git a/src/input/csv.c b/src/input/csv.c index af04ae21..3a42fc9b 100644 --- a/src/input/csv.c +++ b/src/input/csv.c @@ -210,6 +210,7 @@ struct context { /* Current samplerate, optionally determined from input data. */ uint64_t samplerate; + uint64_t calc_samplerate; double prev_timestamp; gboolean samplerate_sent; @@ -281,10 +282,12 @@ static int flush_samplerate(const struct sr_input *in) struct sr_config *src; inc = in->priv; - if (inc->samplerate && !inc->samplerate_sent) { + if (!inc->calc_samplerate && inc->samplerate) + inc->calc_samplerate = inc->samplerate; + if (inc->calc_samplerate && !inc->samplerate_sent) { packet.type = SR_DF_META; packet.payload = &meta; - src = sr_config_new(SR_CONF_SAMPLERATE, g_variant_new_uint64(inc->samplerate)); + src = sr_config_new(SR_CONF_SAMPLERATE, g_variant_new_uint64(inc->calc_samplerate)); meta.config = g_slist_append(NULL, src); sr_session_send(in->sdi, &packet); g_slist_free(meta.config); @@ -347,6 +350,7 @@ static int flush_logic_samples(const struct sr_input *in) return rc; inc->datafeed_buf_fill = 0; + return SR_OK; } @@ -365,6 +369,7 @@ static int queue_logic_samples(const struct sr_input *in) if (rc != SR_OK) return rc; } + return SR_OK; } @@ -440,6 +445,7 @@ static int flush_analog_samples(const struct sr_input *in) } inc->analog_datafeed_buf_fill = 0; + return SR_OK; } @@ -458,6 +464,7 @@ static int queue_analog_samples(const struct sr_input *in) if (rc != SR_OK) return rc; } + return SR_OK; } @@ -725,6 +732,7 @@ static const struct column_details *lookup_column_details(struct context *inc, s return NULL; if (!nr || nr > inc->column_want_count) return NULL; + return &inc->column_details[nr - 1]; } @@ -748,7 +756,7 @@ static void strip_comment(char *buf, const GString *prefix) } /** - * @brief Splits a text line into a set of columns. + * Splits a text line into a set of columns. * * @param[in] buf The input text line to split. * @param[in] inc The input module's context. @@ -763,7 +771,7 @@ static char **split_line(char *buf, struct context *inc) } /** - * @brief Parse a multi-bit field into several logic channels. + * Parse a multi-bit field into several logic channels. * * @param[in] column The input text, a run of bin/hex/oct digits. * @param[in] inc The input module's context. @@ -873,7 +881,7 @@ static int parse_logic(const char *column, struct context *inc, } /** - * @brief Parse a floating point text into an analog value. + * Parse a floating point text into an analog value. * * @param[in] column The input text, a floating point number. * @param[in] inc The input module's context. @@ -922,7 +930,7 @@ static int parse_analog(const char *column, struct context *inc, } /** - * @brief Parse a timestamp text, auto-determine samplerate. + * Parse a timestamp text, auto-determine samplerate. * * @param[in] column The input text, a floating point number. * @param[in] inc The input module's context. @@ -973,13 +981,13 @@ static int parse_timestamp(const char *column, struct context *inc, * reduced rounding errors which result in odd rates. * - Support other formats ("2 ms" or similar)? */ - if (inc->samplerate) + if (inc->calc_samplerate) return SR_OK; ret = sr_atod_ascii(column, &ts); if (ret != SR_OK) ts = 0.0; if (!ts) { - sr_warn("Cannot convert timestamp text %s in line %zu (or zero value).", + sr_info("Cannot convert timestamp text %s in line %zu (or zero value).", column, inc->line_number); inc->prev_timestamp = 0.0; return SR_OK; @@ -1004,14 +1012,14 @@ static int parse_timestamp(const char *column, struct context *inc, rate += 0.5; rate = (uint64_t)rate; sr_dbg("Rate from timestamp %g in line %zu.", rate, inc->line_number); - inc->samplerate = rate; + inc->calc_samplerate = rate; inc->prev_timestamp = 0.0; return SR_OK; } /** - * @brief Parse routine which ignores the input text. + * Parse routine which ignores the input text. * * This routine exists to unify dispatch code paths, mapping input file * columns' data types to their respective parse routines. @@ -1022,6 +1030,7 @@ static int parse_ignore(const char *column, struct context *inc, (void)column; (void)inc; (void)details; + return SR_OK; } @@ -1153,6 +1162,7 @@ static int format_match(GHashTable *metadata, unsigned int *confidence) if (!status) return SR_ERR; + return SR_OK; } @@ -1385,7 +1395,7 @@ static int initial_parse(const struct sr_input *in, GString *buf) ret = SR_ERR; goto out; } - sr_dbg("DIAG Got %zu columns in text line: %s.", num_columns, line); + sr_dbg("Got %zu columns in text line: %s.", num_columns, line); /* * Interpret the user provided column format specs. This might @@ -1785,7 +1795,7 @@ static struct sr_option options[] = { }, [OPT_HEADER] = { "header", "Get channel names from first line.", - "Use the first processed line's column captions (when available) as channel names. Off by default", + "Use the first processed line's column captions (when available) as channel names. Enabled by default.", NULL, NULL, }, [OPT_SAMPLERATE] = { @@ -1822,7 +1832,7 @@ static const struct sr_option *get_options(void) l = g_slist_append(l, g_variant_ref_sink(g_variant_new_string("oct"))); options[OPT_SINGLE_FMT].values = l; options[OPT_START_LINE].def = g_variant_ref_sink(g_variant_new_uint32(1)); - options[OPT_HEADER].def = g_variant_ref_sink(g_variant_new_boolean(FALSE)); + options[OPT_HEADER].def = g_variant_ref_sink(g_variant_new_boolean(TRUE)); options[OPT_SAMPLERATE].def = g_variant_ref_sink(g_variant_new_uint64(0)); options[OPT_COL_SEP].def = g_variant_ref_sink(g_variant_new_string(",")); options[OPT_COMMENT].def = g_variant_ref_sink(g_variant_new_string(";"));