From 0b9fe2236effde0f53c66a5aa3ed7d7bbae35b6c Mon Sep 17 00:00:00 2001 From: DreamSourceLab Date: Fri, 21 Jul 2017 15:11:09 +0800 Subject: [PATCH] fix save/export issue when sample depth greater than 4G, or part of channels enabled --- DSView/pv/data/logicsnapshot.cpp | 18 ++++++++++-------- DSView/pv/dialogs/storeprogress.cpp | 7 +++---- libsigrok4DSL/output/csv.c | 6 ++++-- libsigrok4DSL/output/gnuplot.c | 5 +++-- libsigrok4DSL/output/vcd.c | 3 ++- 5 files changed, 22 insertions(+), 17 deletions(-) diff --git a/DSView/pv/data/logicsnapshot.cpp b/DSView/pv/data/logicsnapshot.cpp index b30187dd..54448bc7 100644 --- a/DSView/pv/data/logicsnapshot.cpp +++ b/DSView/pv/data/logicsnapshot.cpp @@ -220,12 +220,15 @@ void LogicSnapshot::append_cross_payload( if (_sample_count >= _total_sample_count) return; + _src_ptr = logic.data; + uint64_t len = logic.length; uint64_t samples = ceil(logic.length * 8.0 / _channel_num); - - if (_sample_count + samples < _total_sample_count) + if (_sample_count + samples < _total_sample_count) { _sample_count += samples; - else + } else { + len = ceil((_total_sample_count - _sample_count) * _channel_num / 8.0); _sample_count = _total_sample_count; + } while (_sample_count > _block_num * LeafBlockSamples) { uint8_t index0 = _block_num / RootScale; @@ -244,9 +247,6 @@ void LogicSnapshot::append_cross_payload( _block_num++; } - _src_ptr = logic.data; - uint64_t len = logic.length; - // bit align while (((_ch_fraction != 0) || (_byte_fraction != 0)) && (len != 0)) { uint8_t *dp_tmp = (uint8_t *)_dest_ptr; @@ -378,10 +378,12 @@ void LogicSnapshot::append_split_payload( if (_sample_cnt[order] >= _total_sample_count) return; - if (_sample_cnt[order] + samples < _total_sample_count) + if (_sample_cnt[order] + samples < _total_sample_count) { _sample_cnt[order] += samples; - else + } else { + samples = _total_sample_count - _sample_cnt[order]; _sample_cnt[order] = _total_sample_count; + } while (_sample_cnt[order] > _block_cnt[order] * LeafBlockSamples) { uint8_t index0 = _block_cnt[order] / RootScale; diff --git a/DSView/pv/dialogs/storeprogress.cpp b/DSView/pv/dialogs/storeprogress.cpp index aa2f2916..a03beb1a 100644 --- a/DSView/pv/dialogs/storeprogress.cpp +++ b/DSView/pv/dialogs/storeprogress.cpp @@ -37,7 +37,7 @@ StoreProgress::StoreProgress(SigSession &session, QWidget *parent) : _info.setText("..."); _progress.setValue(0); - _progress.setMaximum(0); + _progress.setMaximum(100); QVBoxLayout* add_layout = new QVBoxLayout(this); add_layout->addWidget(&_info, 0, Qt::AlignCenter); @@ -114,9 +114,8 @@ void StoreProgress::on_progress_updated() { const std::pair p = _store_session.progress(); assert(p.first <= p.second); - - _progress.setValue(p.first); - _progress.setMaximum(p.second); + int percent = p.first * 1.0 / p.second * 100; + _progress.setValue(percent); const QString err = _store_session.error(); if (!err.isEmpty()) { diff --git a/libsigrok4DSL/output/csv.c b/libsigrok4DSL/output/csv.c index 37241ca4..bb48873e 100644 --- a/libsigrok4DSL/output/csv.c +++ b/libsigrok4DSL/output/csv.c @@ -93,7 +93,8 @@ static int init(struct sr_output *o, GHashTable *options) if (!ch->enabled) continue; ctx->channel_index[i] = ch->index; - ctx->mask |= (1 << ch->index); + //ctx->mask |= (1 << ch->index); + ctx->mask |= (1 << i); ctx->channel_vdiv[i] = ch->vdiv * ch->vfactor >= 500 ? ch->vdiv * ch->vfactor / 100.0f : ch->vdiv * ch->vfactor * 10.0f; ctx->channel_vpos[i] = ch->vdiv * ch->vfactor >= 500 ? ch->vpos / 1000 : ch->vpos; i++; @@ -217,7 +218,8 @@ static int receive(const struct sr_output *o, const struct sr_datafeed_packet *p continue; g_string_append_printf(*out, "%0.10g", (ctx->index-1)*1.0/ctx->samplerate); for (j = 0; j < ctx->num_enabled_channels; j++) { - idx = ctx->channel_index[j]; + //idx = ctx->channel_index[j]; + idx = j; p = logic->data + i + idx / 8; c = *p & (1 << (idx % 8)); g_string_append_c(*out, ctx->separator); diff --git a/libsigrok4DSL/output/gnuplot.c b/libsigrok4DSL/output/gnuplot.c index c5731714..3491eb3b 100644 --- a/libsigrok4DSL/output/gnuplot.c +++ b/libsigrok4DSL/output/gnuplot.c @@ -191,11 +191,12 @@ static int receive(const struct sr_output *o, const struct sr_datafeed_packet *p memcpy(ctx->prevsample, sample, logic->unitsize); /* The first column is a counter (needed for gnuplot). */ - g_string_append_printf(*out, "%"PRIu64"\t", ctx->samplecount); + g_string_append_printf(*out, "%"PRIu64"\t", ctx->samplecount-1); /* The next columns are the values of all channels. */ for (p = 0; p < ctx->num_enabled_channels; p++) { - idx = ctx->channel_index[p]; + //idx = ctx->channel_index[p]; + idx = p; curbit = (sample[idx / 8] & ((uint8_t) (1 << (idx % 8)))) >> (idx % 8); g_string_append_printf(*out, "%d ", curbit); } diff --git a/libsigrok4DSL/output/vcd.c b/libsigrok4DSL/output/vcd.c index 43b4b4c2..a622368a 100644 --- a/libsigrok4DSL/output/vcd.c +++ b/libsigrok4DSL/output/vcd.c @@ -201,7 +201,8 @@ static int receive(const struct sr_output *o, const struct sr_datafeed_packet *p timestamp_written = FALSE; for (p = 0; p < ctx->num_enabled_channels; p++) { - index = ctx->channel_index[p]; + //index = ctx->channel_index[p]; + index = p; curbit = ((unsigned)sample[index / 8] >> (index % 8)) & 1;