X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=src%2Foutput%2Fcsv.c;h=426cb6ed344ed3040bb7adb9a84f6c3844695ab1;hb=aa0979482f6e7c269609bb2c22d7d75a2845ac75;hp=a6e835ad28847514b5cb8f2442c9ebabc65d29fc;hpb=cad447d21a28438cd34bcfa053383e7487b16b35;p=libsigrok.git diff --git a/src/output/csv.c b/src/output/csv.c index a6e835ad..426cb6ed 100644 --- a/src/output/csv.c +++ b/src/output/csv.c @@ -14,8 +14,7 @@ * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * along with this program; if not, see . */ /* @@ -217,7 +216,7 @@ static GString *gen_header(const struct sr_output *o, struct sr_channel *ch; GVariant *gvar; GString *header; - GSList *l; + GSList *channels, *l; unsigned int num_channels, i; uint64_t samplerate = 0, sr; char *samplerate_s; @@ -257,18 +256,20 @@ static GString *gen_header(const struct sr_output *o, ctx->title, ctime(&hdr->starttime.tv_sec)); /* Columns / channels */ - num_channels = g_slist_length(o->sdi->channels); + channels = o->sdi ? o->sdi->channels : NULL; + num_channels = g_slist_length(channels); g_string_append_printf(header, "%s Channels (%d/%d):", ctx->comment, ctx->num_analog_channels + ctx->num_logic_channels, num_channels); - for (i = 0, l = o->sdi->channels; l; l = l->next, i++) { + for (l = channels; l; l = l->next) { ch = l->data; if (ch->enabled) g_string_append_printf(header, " %s,", ch->name); } - if (o->sdi->channels) + if (channels) { /* Drop last separator. */ g_string_truncate(header, header->len - 1); + } g_string_append_printf(header, "\n"); if (samplerate != 0) { samplerate_s = sr_samplerate_string(samplerate); @@ -379,11 +380,11 @@ static void process_logic(struct context *ctx, for (j = ch = 0; ch < ctx->num_logic_channels; j++) { if (ctx->channels[j].ch->type == SR_CHANNEL_LOGIC) { - for (i = 0; i <= logic->length - logic->unitsize; i += logic->unitsize) { - sample = logic->data + i; - idx = ctx->channels[ch].ch->index; + for (i = 0; i < num_samples; i++) { + sample = logic->data + i * logic->unitsize; + idx = ctx->channels[j].ch->index; if (ctx->label_do && !ctx->label_names) - ctx->channels[i].label = "logic"; + ctx->channels[j].label = "logic"; ctx->logic_samples[i * ctx->num_logic_channels + ch] = sample[idx / 8] & (1 << (idx % 8)); } ch++; @@ -458,7 +459,7 @@ static void dump_saved_values(struct context *ctx, GString **out) } if (ctx->time) - g_string_append_printf(*out, "%lu%s", + g_string_append_printf(*out, "%" PRIu64 "%s", ctx->sample_time, ctx->value); for (j = 0; j < num_channels; j++) { @@ -579,7 +580,7 @@ static int receive(const struct sr_output *o, break; case SR_DF_FRAME_BEGIN: *out = g_string_new(ctx->frame); - /* And then fall through to... */ + /* Fallthrough */ case SR_DF_END: /* Got to end of frame/session with part of the data. */ if (ctx->channels_seen) @@ -609,6 +610,7 @@ static int cleanup(struct sr_output *o) g_free((gpointer)ctx->frame); g_free((gpointer)ctx->comment); g_free((gpointer)ctx->gnuplot); + g_free((gpointer)ctx->value); g_free(ctx->previous_sample); g_free(ctx->channels); g_free(o->priv); @@ -623,7 +625,7 @@ static struct sr_option options[] = { {"scale", "scale", "Scale gnuplot graphs", NULL, NULL}, {"value", "Value separator", "Character to print between values", NULL, NULL}, {"record", "Record separator", "String to print between records", NULL, NULL}, - {"frame", "Frame seperator", "String to print between frames", NULL, NULL}, + {"frame", "Frame separator", "String to print between frames", NULL, NULL}, {"comment", "Comment start string", "String used at start of comment lines", NULL, NULL}, {"header", "Output header", "Output header comment with capture metdata", NULL, NULL}, {"label", "Label values", "Type of column labels", NULL, NULL},