From 44add386d16e6816d816e14ea206ace5cbcc3d94 Mon Sep 17 00:00:00 2001 From: dreamsourcelabTAI Date: Tue, 14 Feb 2023 11:19:57 +0800 Subject: [PATCH] fix: Files with disabled channels are loaded incorrectly --- DSView/pv/storesession.cpp | 57 +++++++++++++++------------- libsigrok4DSL/session_driver.c | 68 +++++++++++++++++++++------------- 2 files changed, 74 insertions(+), 51 deletions(-) diff --git a/DSView/pv/storesession.cpp b/DSView/pv/storesession.cpp index 2b457fc9..4a6555b6 100644 --- a/DSView/pv/storesession.cpp +++ b/DSView/pv/storesession.cpp @@ -376,42 +376,47 @@ void StoreSession::save_dso(pv::data::DsoSnapshot *dso_snapshot) { char chunk_name[20] = {0}; int ret = SR_ERR; - - int ch_type = -1; - for(auto s : _session->get_signals()) { - ch_type = s->get_type(); - break; - } - + uint64_t size = dso_snapshot->get_sample_count(); int ch_num = dso_snapshot->get_channel_num(); _unit_count = size * ch_num; - for (int i = 0; !_canceled && ch_type != -1 && i < ch_num; i++) { - - const uint8_t *data_buffer = dso_snapshot->get_samples(0, 0, i); - - snprintf(chunk_name, 19, "data/%d", i); - ret = m_zipDoc.AddFromBuffer(chunk_name, (const char*)data_buffer, size) ? SR_OK : -1; + for(auto s : _session->get_signals()) + { + if (s->get_type() == SR_CHANNEL_DSO) { + int ch_index = s->get_index(); + + if (!dso_snapshot->has_data(ch_index)) + continue; - if (ret != SR_OK) { - if (!_has_error) { - _has_error = true; - _error = L_S(STR_PAGE_DLG, S_ID(IDS_MSG_STORESESS_SAVEPROC_ERROR2), - "Failed to create zip file. Please check write permission of this path."); + if (_canceled) + break; + + const uint8_t *data_buffer = dso_snapshot->get_samples(0, 0, ch_index); + + snprintf(chunk_name, 19, "O-%d/0", ch_index); + ret = m_zipDoc.AddFromBuffer(chunk_name, (const char*)data_buffer, size) ? SR_OK : -1; + + if (ret != SR_OK) { + if (!_has_error) { + _has_error = true; + _error = L_S(STR_PAGE_DLG, S_ID(IDS_MSG_STORESESS_SAVEPROC_ERROR2), + "Failed to create zip file. Please check write permission of this path."); + } + progress_updated(); + if (_has_error) + QFile::remove(_file_name); + return; } + + _units_stored += size; progress_updated(); - if (_has_error) - QFile::remove(_file_name); - return; } - _units_stored += size; - progress_updated(); - } + } progress_updated(); - if (_canceled || size == 0){ + if (_canceled || size == 0 || ch_num == 0){ QFile::remove(_file_name); } else { @@ -557,8 +562,10 @@ bool StoreSession::meta_gen(data::Snapshot *snapshot, std::string &str) for (l = _session->get_device()->get_channels(); l; l = l->next) { probe = (struct sr_channel *)l->data; + if (!snapshot->has_data(probe->index)) continue; + if (mode == LOGIC && !probe->enabled) continue; diff --git a/libsigrok4DSL/session_driver.c b/libsigrok4DSL/session_driver.c index c3407660..350813d2 100644 --- a/libsigrok4DSL/session_driver.c +++ b/libsigrok4DSL/session_driver.c @@ -418,21 +418,23 @@ static int receive_data_logic_dso_v2(int fd, int revents, const struct sr_dev_in struct sr_datafeed_packet packet; struct sr_datafeed_logic logic; struct sr_datafeed_dso dso; - GSList *l; + int ret; char file_name[32]; - GSList *pl; int channel; - int ch_index, ch_index2; + int ch_index, malloc_chan_index; struct session_packet_buffer *pack_buffer; unz_file_info64 fileInfo; char szFilePath[15]; int bToEnd; - int chIndex; + int read_chan_index; int chan_num; uint8_t *p_wr; uint8_t *p_rd; int byte_align; + int dir_index; + int bCheckFile; + const int file_max_channel_count = 128; assert(sdi); assert(sdi->priv); @@ -498,7 +500,8 @@ static int receive_data_logic_dso_v2(int fd, int revents, const struct sr_dev_in pack_buffer = vdev->packet_buffer; // Make packet. - chIndex = 0; + read_chan_index = 0; + dir_index = 0; while (pack_buffer->post_len < pack_buffer->post_buf_len) { @@ -509,16 +512,27 @@ static int receive_data_logic_dso_v2(int fd, int revents, const struct sr_dev_in break; } - for (ch_index = 0; ch_index < chan_num; ch_index++) + for (ch_index = 0; ch_index < chan_num; ch_index++) { - if (sdi->mode == LOGIC){ - snprintf(file_name, sizeof(file_name)-1, "L-%d/%d", ch_index, vdev->cur_block); - } - else if (sdi->mode == DSO){ - snprintf(file_name, sizeof(file_name)-1, "data/%d", ch_index); + bCheckFile = 0; + + while (1) + { + if (sdi->mode == LOGIC) + snprintf(file_name, sizeof(file_name)-1, "L-%d/%d", dir_index++, vdev->cur_block); + else if (sdi->mode == DSO) + snprintf(file_name, sizeof(file_name)-1, "O-%d/0", dir_index++); + + if (unzLocateFile(vdev->archive, file_name, 0) == UNZ_OK){ + bCheckFile = 1; + break; + } + else if (dir_index > file_max_channel_count){ + break; + } } - if (unzLocateFile(vdev->archive, file_name, 0) != UNZ_OK) + if (!bCheckFile) { sr_err("cant't locate zip inner file:\"%s\"", file_name); send_error_packet(sdi, vdev, &packet); @@ -538,15 +552,15 @@ static int receive_data_logic_dso_v2(int fd, int revents, const struct sr_dev_in if (pack_buffer->block_data_len > pack_buffer->block_buf_len) { - for (ch_index2 = 0; ch_index2 < chan_num; ch_index2++){ + for (malloc_chan_index = 0; malloc_chan_index < chan_num; malloc_chan_index++){ // Release the old buffer. - if (pack_buffer->block_bufs[ch_index2] != NULL){ - g_free(pack_buffer->block_bufs[ch_index2]); - pack_buffer->block_bufs[ch_index2] = NULL; + if (pack_buffer->block_bufs[malloc_chan_index] != NULL){ + g_free(pack_buffer->block_bufs[malloc_chan_index]); + pack_buffer->block_bufs[malloc_chan_index] = NULL; } - pack_buffer->block_bufs[ch_index2] = g_try_malloc0(pack_buffer->block_data_len + 1); - if (pack_buffer->block_bufs[ch_index2] == NULL){ + pack_buffer->block_bufs[malloc_chan_index] = g_try_malloc0(pack_buffer->block_data_len + 1); + if (pack_buffer->block_bufs[malloc_chan_index] == NULL){ sr_err("%s: block buffer malloc failed", __func__); send_error_packet(sdi, vdev, &packet); return FALSE; @@ -588,18 +602,18 @@ static int receive_data_logic_dso_v2(int fd, int revents, const struct sr_dev_in } p_wr = (uint8_t*)pack_buffer->post_buf + pack_buffer->post_len; - p_rd = (uint8_t*)pack_buffer->block_bufs[chIndex] + pack_buffer->block_read_positions[chIndex]; + p_rd = (uint8_t*)pack_buffer->block_bufs[read_chan_index] + pack_buffer->block_read_positions[read_chan_index]; *p_wr = *p_rd; pack_buffer->post_len++; - pack_buffer->block_read_positions[chIndex]++; + pack_buffer->block_read_positions[read_chan_index]++; - if (pack_buffer->block_read_positions[chIndex] % byte_align == 0 - || pack_buffer->block_read_positions[chIndex] == pack_buffer->block_data_len) + if (pack_buffer->block_read_positions[read_chan_index] % byte_align == 0 + || pack_buffer->block_read_positions[read_chan_index] == pack_buffer->block_data_len) { - chIndex++; + read_chan_index++; - if (pack_buffer->block_read_positions[chIndex] == pack_buffer->block_data_len){ + if (pack_buffer->block_read_positions[read_chan_index] == pack_buffer->block_data_len){ sr_info("Block read end."); if (vdev->cur_block < vdev->num_blocks){ sr_err("%s", "The block data is not align."); @@ -607,8 +621,9 @@ static int receive_data_logic_dso_v2(int fd, int revents, const struct sr_dev_in } } - if (chIndex == chan_num){ - chIndex = 0; + // Each channel's data is ready. + if (read_chan_index == chan_num){ + read_chan_index = 0; pack_buffer->block_chan_read_pos += byte_align; } } @@ -637,6 +652,7 @@ static int receive_data_logic_dso_v2(int fd, int revents, const struct sr_dev_in dso.data = pack_buffer->post_buf; } + // Send data back. ds_data_forward(sdi, &packet); pack_buffer->post_len = 0; }