From 3226adfc7de65ebf78f391578f8e53db55c6f460 Mon Sep 17 00:00:00 2001 From: dreamsourcelabTAI Date: Sat, 17 Jun 2023 11:30:33 +0800 Subject: [PATCH] fix: Failed to export data with each format --- DSView/pv/storesession.cpp | 11 ++++++++--- libsigrok4DSL/input/in_binary.c | 2 ++ libsigrok4DSL/input/in_vcd.c | 2 ++ libsigrok4DSL/input/in_wav.c | 2 ++ libsigrok4DSL/output/csv.c | 8 +++++++- libsigrok4DSL/output/gnuplot.c | 5 +++++ libsigrok4DSL/output/output.c | 5 +++++ libsigrok4DSL/output/srzip.c | 5 +++++ libsigrok4DSL/output/vcd.c | 5 +++++ 9 files changed, 41 insertions(+), 4 deletions(-) diff --git a/DSView/pv/storesession.cpp b/DSView/pv/storesession.cpp index 79e9197d..2c1b788b 100644 --- a/DSView/pv/storesession.cpp +++ b/DSView/pv/storesession.cpp @@ -769,8 +769,13 @@ void StoreSession::export_proc(data::Snapshot *snapshot) output.module = (sr_output_module*) _outModule; output.sdi = _session->get_device()->inst(); output.param = NULL; - if(_outModule->init) - _outModule->init(&output, params); + + if(_outModule->init){ + if(_outModule->init(&output, params) != SR_OK){ + dsv_err("Failed to init export module."); + return; + } + } QFile file(_file_name); file.open(QIODevice::WriteOnly | QIODevice::Text); @@ -836,7 +841,7 @@ void StoreSession::export_proc(data::Snapshot *snapshot) g_slist_free(meta.config); if (channel_type == SR_CHANNEL_LOGIC) { - _unit_count = logic_snapshot->get_sample_count(); + _unit_count = logic_snapshot->get_ring_sample_count(); int blk_num = logic_snapshot->get_block_num(); bool sample; std::vector buf_vec; diff --git a/libsigrok4DSL/input/in_binary.c b/libsigrok4DSL/input/in_binary.c index 5594a6db..1d659209 100644 --- a/libsigrok4DSL/input/in_binary.c +++ b/libsigrok4DSL/input/in_binary.c @@ -25,6 +25,7 @@ #include #include #include "../log.h" +#include /* Message logging helpers with subsystem-specific prefix string. */ @@ -60,6 +61,7 @@ static int init(struct sr_input *in, const char *filename) sr_err("Input format context malloc failed."); return SR_ERR_MALLOC; } + memset(ctx, 0, sizeof(struct context)); num_probes = DEFAULT_NUM_PROBES; ctx->samplerate = 0; diff --git a/libsigrok4DSL/input/in_vcd.c b/libsigrok4DSL/input/in_vcd.c index 3400cb34..ffce2b37 100644 --- a/libsigrok4DSL/input/in_vcd.c +++ b/libsigrok4DSL/input/in_vcd.c @@ -65,6 +65,7 @@ #include #include #include "../log.h" +#include /* Message logging helpers with subsystem-specific prefix string. */ @@ -334,6 +335,7 @@ static int init(struct sr_input *in, const char *filename) sr_err("Input format context malloc failed."); return SR_ERR_MALLOC; } + memset(ctx, 0, sizeof(struct context)); num_probes = DEFAULT_NUM_PROBES; ctx->samplerate = 0; diff --git a/libsigrok4DSL/input/in_wav.c b/libsigrok4DSL/input/in_wav.c index ff6a3dc4..de16e513 100644 --- a/libsigrok4DSL/input/in_wav.c +++ b/libsigrok4DSL/input/in_wav.c @@ -25,6 +25,7 @@ #include #include #include "../log.h" +#include #undef LOG_PREFIX #define LOG_PREFIX "input/wav: " @@ -99,6 +100,7 @@ static int init(struct sr_input *in, const char *filename) sr_err("%s,ERROR:failed to alloc memory.", __func__); return SR_ERR_MALLOC; } + memset(ctx, 0, sizeof(struct context)); /* Create a virtual device. */ in->sdi = sr_dev_inst_new(LOGIC, SR_ST_ACTIVE, NULL, NULL, NULL); diff --git a/libsigrok4DSL/output/csv.c b/libsigrok4DSL/output/csv.c index b875ae5e..7ea13cf7 100644 --- a/libsigrok4DSL/output/csv.c +++ b/libsigrok4DSL/output/csv.c @@ -25,6 +25,10 @@ #include #include "../config.h" /* Needed for PACKAGE_STRING and others. */ #include "../log.h" +#include + +#undef LOG_PREFIX +#define LOG_PREFIX "csv: " struct context { unsigned int num_enabled_channels; @@ -60,7 +64,7 @@ struct context { static int init(struct sr_output *o, GHashTable *options) { - struct context *ctx; + struct context *ctx = NULL; struct sr_channel *ch; GSList *l; int i; @@ -74,6 +78,7 @@ static int init(struct sr_output *o, GHashTable *options) sr_err("%s,ERROR:failed to alloc memory.", __func__); return SR_ERR; } + memset(ctx, 0, sizeof(struct context)); o->priv = ctx; ctx->separator = ','; @@ -90,6 +95,7 @@ static int init(struct sr_output *o, GHashTable *options) continue; ctx->num_enabled_channels++; } + ctx->channel_index = malloc(sizeof(int) * ctx->num_enabled_channels); ctx->channel_unit = malloc(sizeof(int) * ctx->num_enabled_channels); ctx->channel_scale = malloc(sizeof(float) * ctx->num_enabled_channels); diff --git a/libsigrok4DSL/output/gnuplot.c b/libsigrok4DSL/output/gnuplot.c index d29ffbc4..1260d009 100644 --- a/libsigrok4DSL/output/gnuplot.c +++ b/libsigrok4DSL/output/gnuplot.c @@ -26,6 +26,10 @@ #include #include "../config.h" /* Needed for PACKAGE_STRING and others. */ #include "../log.h" +#include + +#undef LOG_PREFIX +#define LOG_PREFIX "gnuplot: " struct context { unsigned int num_enabled_channels; @@ -61,6 +65,7 @@ static int init(struct sr_output *o, GHashTable *options) sr_err("%s,ERROR:failed to alloc memory.", __func__); return SR_ERR; } + memset(ctx, 0, sizeof(struct context)); o->priv = ctx; ctx->num_enabled_channels = 0; diff --git a/libsigrok4DSL/output/output.c b/libsigrok4DSL/output/output.c index d99bdcb2..455514c3 100644 --- a/libsigrok4DSL/output/output.c +++ b/libsigrok4DSL/output/output.c @@ -21,8 +21,12 @@ #include "../libsigrok-internal.h" #include #include "../log.h" +#include +#undef LOG_PREFIX +#define LOG_PREFIX "output " + /** * @file * @@ -262,6 +266,7 @@ SR_API const struct sr_output *sr_output_new(const struct sr_output_module *omod sr_err("%s,ERROR:failed to alloc memory.", __func__); return SR_ERR; } + memset(op, 0, sizeof(struct sr_output)); op->module = omod; op->sdi = sdi; diff --git a/libsigrok4DSL/output/srzip.c b/libsigrok4DSL/output/srzip.c index 9d59e0f4..2f0d8bca 100755 --- a/libsigrok4DSL/output/srzip.c +++ b/libsigrok4DSL/output/srzip.c @@ -29,6 +29,10 @@ #include #include "../log.h" #include "../version.h" +#include + +#undef LOG_PREFIX +#define LOG_PREFIX "srzip: " struct out_context { uint64_t samplerate; @@ -49,6 +53,7 @@ static int init(struct sr_output *o, GHashTable *options) sr_err("%s,ERROR:failed to alloc memory.", __func__); return SR_ERR; } + memset(outc, 0, sizeof(struct out_context)); o->priv = outc; outc->zipArchive = NULL; diff --git a/libsigrok4DSL/output/vcd.c b/libsigrok4DSL/output/vcd.c index a4018153..d9b825f7 100644 --- a/libsigrok4DSL/output/vcd.c +++ b/libsigrok4DSL/output/vcd.c @@ -26,6 +26,10 @@ #include #include "../config.h" /* Needed for PACKAGE and others. */ #include "../log.h" +#include + +#undef LOG_PREFIX +#define LOG_PREFIX "vcd: " struct context { int num_enabled_channels; @@ -66,6 +70,7 @@ static int init(struct sr_output *o, GHashTable *options) sr_err("%s,ERROR:failed to alloc memory.", __func__); return SR_ERR; } + memset(ctx, 0, sizeof(struct context)); o->priv = ctx; ctx->num_enabled_channels = num_enabled_channels;