diff --git a/DSView/pv/data/analogsnapshot.cpp b/DSView/pv/data/analogsnapshot.cpp index 1a456ba2..cb8e2f0a 100644 --- a/DSView/pv/data/analogsnapshot.cpp +++ b/DSView/pv/data/analogsnapshot.cpp @@ -45,6 +45,7 @@ AnalogSnapshot::AnalogSnapshot() : { memset(_envelope_levels, 0, sizeof(_envelope_levels)); _unit_pitch = 0; + _data = NULL; } AnalogSnapshot::~AnalogSnapshot() @@ -86,6 +87,16 @@ void AnalogSnapshot::init_all() } } +void AnalogSnapshot::free_data() +{ + Snapshot::free_data(); + + if (_data != NULL){ + free(_data); + _data = NULL; + } +} + void AnalogSnapshot::clear() { std::lock_guard lock(_mutex); @@ -390,5 +401,9 @@ uint64_t AnalogSnapshot::get_block_size(int block_index) } } +void* AnalogSnapshot::get_data(){ + return _data; +} + } // namespace data } // namespace pv diff --git a/DSView/pv/data/analogsnapshot.h b/DSView/pv/data/analogsnapshot.h index 76a3d17b..3356f89a 100644 --- a/DSView/pv/data/analogsnapshot.h +++ b/DSView/pv/data/analogsnapshot.h @@ -107,17 +107,19 @@ public: int get_block_num(); uint64_t get_block_size(int block_index); + void* get_data(); + private: void append_data(void *data, uint64_t samples, uint16_t pitch); void free_envelop(); void reallocate_envelope(Envelope &l); void append_payload_to_envelope_levels(); - - + void free_data(); private: + void *_data; struct Envelope _envelope_levels[DS_MAX_ANALOG_PROBES_NUM][ScaleStepCount]; - friend class AnalogSnapshotTest::Basic; + friend class AnalogSnapshotTest::Basic; }; } // namespace data diff --git a/DSView/pv/data/dsosnapshot.cpp b/DSView/pv/data/dsosnapshot.cpp index 5cb535be..5faaab6f 100644 --- a/DSView/pv/data/dsosnapshot.cpp +++ b/DSView/pv/data/dsosnapshot.cpp @@ -27,6 +27,7 @@ #include "dsosnapshot.h" #include "../dsvdef.h" +#include "../log.h" using namespace std; @@ -42,11 +43,12 @@ const uint64_t DsoSnapshot::EnvelopeDataUnit = 4*1024; // bytes const int DsoSnapshot::VrmsScaleFactor = 1 << 8; DsoSnapshot::DsoSnapshot() : - Snapshot(sizeof(uint16_t), 1, 1), - _envelope_en(false), - _envelope_done(false), - _instant(false) -{ + Snapshot(sizeof(uint16_t), 1, 1) +{ + _envelope_en = false; + _envelope_done = false; + _instant = false; + memset(_envelope_levels, 0, sizeof(_envelope_levels)); } @@ -98,20 +100,31 @@ void DsoSnapshot::clear() _have_data = false; } +void DsoSnapshot::free_data() +{ + Snapshot::free_data(); + + for(auto ptr : _ch_data){ + free(ptr); + } + _ch_data.clear(); +} + void DsoSnapshot::first_payload(const sr_datafeed_dso &dso, uint64_t total_sample_count, std::map ch_enable, bool instant) { bool re_alloc = false; unsigned int channel_num = 0; + for (auto& iter:ch_enable) { if (iter.second) channel_num++; } assert(channel_num != 0); - if (total_sample_count != _total_sample_count || - channel_num != _channel_num) + if (total_sample_count != _total_sample_count || channel_num != _channel_num){ re_alloc = true; + } _total_sample_count = total_sample_count; _channel_num = channel_num; @@ -120,17 +133,30 @@ void DsoSnapshot::first_payload(const sr_datafeed_dso &dso, uint64_t total_sampl bool isOk = true; uint64_t size = _total_sample_count * _channel_num + sizeof(uint64_t); + if (re_alloc || size != _capacity) { free_data(); - _data = malloc(size); - if (_data) { + + for (int ch=0; ch<_channel_num; ch++){ + uint8_t *buf = (uint8_t*)malloc(_total_sample_count + 1); + if (buf == NULL){ + isOk = false; + dsv_err("DsoSnapshot::first_payload, Malloc memory failed!"); + break; + } + _ch_data.push_back(buf); + } + + if (isOk) { free_envelop(); + for (unsigned int i = 0; i < _channel_num; i++) { uint64_t envelop_count = _total_sample_count / EnvelopeScaleFactor; + for (unsigned int level = 0; level < ScaleStepCount; level++) { - envelop_count = ((envelop_count + EnvelopeDataUnit - 1) / - EnvelopeDataUnit) * EnvelopeDataUnit; + envelop_count = ((envelop_count + EnvelopeDataUnit - 1) / EnvelopeDataUnit) * EnvelopeDataUnit; _envelope_levels[i][level].samples = (EnvelopeSample*)malloc(envelop_count * sizeof(EnvelopeSample)); + if (!_envelope_levels[i][level].samples) { isOk = false; break; @@ -140,8 +166,6 @@ void DsoSnapshot::first_payload(const sr_datafeed_dso &dso, uint64_t total_sampl if (!isOk) break; } - } else { - isOk = true; } } @@ -150,7 +174,8 @@ void DsoSnapshot::first_payload(const sr_datafeed_dso &dso, uint64_t total_sampl _memory_failed = false; append_payload(dso); _last_ended = false; - } else { + } + else { free_data(); free_envelop(); _memory_failed = true; @@ -161,7 +186,7 @@ void DsoSnapshot::append_payload(const sr_datafeed_dso &dso) { std::lock_guard lock(_mutex); - if (_channel_num > 0 && dso.num_samples != 0) { + if (_channel_num > 0 && dso.num_samples > 0) { append_data(dso.data, dso.num_samples, _instant); // Generate the first mip-map from the data @@ -174,16 +199,36 @@ void DsoSnapshot::append_payload(const sr_datafeed_dso &dso) void DsoSnapshot::append_data(void *data, uint64_t samples, bool instant) { - if (instant) { + uint64_t old_sample_count = _sample_count; + + if (instant) { if(_sample_count + samples > _total_sample_count) samples = _total_sample_count - _sample_count; - memcpy((uint8_t*)_data + _sample_count * _channel_num, data, samples*_channel_num); _sample_count += samples; - } else { - memcpy((uint8_t*)_data, data, samples*_channel_num); + } + else { _sample_count = samples; } + assert(samples <= _total_sample_count); + + uint8_t *end = (uint8_t*)data + samples * _channel_num; + + for (int ch = 0; ch < _channel_num; ch++) + { + uint8_t *src = (uint8_t*)data + ch; + uint8_t *dest = _ch_data[ch]; + + if (instant){ + dest += old_sample_count; + } + + while (src < end) + { + *dest++ = *src; + src += _channel_num; + } + } } void DsoSnapshot::enable_envelope(bool enable) @@ -194,20 +239,21 @@ void DsoSnapshot::enable_envelope(bool enable) _envelope_en = enable; } -const uint8_t *DsoSnapshot::get_samples( - int64_t start_sample, int64_t end_sample, uint16_t index) +const uint8_t *DsoSnapshot::get_samples(int64_t start_sample, int64_t end_sample, uint16_t index) { - std::lock_guard lock(_mutex); - (void)end_sample; + std::lock_guard lock(_mutex); assert(start_sample >= 0); - assert(start_sample < (int64_t)sample_count()); + assert(start_sample < (int64_t)_sample_count); assert(end_sample >= 0); - assert(end_sample < (int64_t)sample_count()); + assert(end_sample < (int64_t)_sample_count); assert(start_sample <= end_sample); + if (index < 0 || index >= _ch_data.size()){ + assert(false); + } - return (uint8_t*)_data + start_sample * _channel_num + index * (_channel_num != 1); + return (uint8_t*)_ch_data[index] + start_sample; } void DsoSnapshot::get_envelope_section(EnvelopeSection &s, @@ -235,9 +281,7 @@ void DsoSnapshot::get_envelope_section(EnvelopeSection &s, s.length = 0; else s.length = end - start; -// s.samples = new EnvelopeSample[s.length]; -// memcpy(s.samples, _envelope_levels[min_level].samples + start, -// s.length * sizeof(EnvelopeSample)); + s.samples = _envelope_levels[probe_index][min_level].samples + start; } @@ -248,8 +292,6 @@ void DsoSnapshot::reallocate_envelope(Envelope &e) if (new_data_length > e.data_length) { e.data_length = new_data_length; -// e.samples = (EnvelopeSample*)realloc(e.samples, -// new_data_length * sizeof(EnvelopeSample)); } } @@ -277,26 +319,23 @@ void DsoSnapshot::append_payload_to_envelope_levels(bool header) dest_ptr = e0.samples + prev_length; // Iterate through the samples to populate the first level mipmap - const uint8_t *const stop_src_ptr = (uint8_t*)_data + - e0.length * EnvelopeScaleFactor * _channel_num; - for (const uint8_t *src_ptr = (uint8_t*)_data + - prev_length * EnvelopeScaleFactor * _channel_num + i; - src_ptr < stop_src_ptr; src_ptr += EnvelopeScaleFactor * _channel_num) + const uint8_t *const stop_src_ptr = (uint8_t*)_ch_data[i] + _sample_count; + const uint8_t *src_ptr = (uint8_t*)_ch_data[i]; + + for (; src_ptr < stop_src_ptr; src_ptr += EnvelopeScaleFactor) { - const uint8_t * begin_src_ptr = - src_ptr; - const uint8_t *const end_src_ptr = - src_ptr + EnvelopeScaleFactor * _channel_num; + const uint8_t *begin_src_ptr = src_ptr; + const uint8_t *const end_src_ptr = begin_src_ptr + EnvelopeScaleFactor; EnvelopeSample sub_sample; sub_sample.min = *begin_src_ptr; sub_sample.max = *begin_src_ptr; - //begin_src_ptr += _channel_num; + while (begin_src_ptr < end_src_ptr) { sub_sample.min = min(sub_sample.min, *begin_src_ptr); sub_sample.max = max(sub_sample.max, *begin_src_ptr); - begin_src_ptr += _channel_num; + begin_src_ptr++; } *dest_ptr++ = sub_sample; } @@ -315,8 +354,6 @@ void DsoSnapshot::append_payload_to_envelope_levels(bool header) e.length = el.length / EnvelopeScaleFactor; // Break off if there are no more samples to computed - // if (e.length == prev_length) - // break; if (e.length == 0) break; if (e.length == prev_length) @@ -328,6 +365,7 @@ void DsoSnapshot::append_payload_to_envelope_levels(bool header) const EnvelopeSample *src_ptr = el.samples + prev_length * EnvelopeScaleFactor; const EnvelopeSample *const end_dest_ptr = e.samples + e.length; + for (dest_ptr = e.samples + prev_length; dest_ptr < end_dest_ptr; dest_ptr++) { @@ -352,7 +390,6 @@ void DsoSnapshot::append_payload_to_envelope_levels(bool header) double DsoSnapshot::cal_vrms(double zero_off, int index) { assert(index >= 0); - //assert(index < _channel_num); // root-meam-squart value double vrms_pre = 0; @@ -360,23 +397,21 @@ double DsoSnapshot::cal_vrms(double zero_off, int index) double tmp; // Iterate through the samples to populate the first level mipmap - const uint8_t *const stop_src_ptr = (uint8_t*)_data + - get_sample_count() * _channel_num; - for (const uint8_t *src_ptr = (uint8_t*)_data + (index % _channel_num); - src_ptr < stop_src_ptr; src_ptr += VrmsScaleFactor * _channel_num) + const uint8_t *const stop_src_ptr = (uint8_t*)_ch_data[index] + _sample_count; + const uint8_t *src_ptr = (uint8_t*)_ch_data[index]; + + for (;src_ptr < stop_src_ptr; src_ptr += VrmsScaleFactor) { - const uint8_t * begin_src_ptr = - src_ptr; - const uint8_t *const end_src_ptr = - src_ptr + VrmsScaleFactor * _channel_num; + const uint8_t * begin_src_ptr = src_ptr; + const uint8_t *const end_src_ptr = src_ptr + VrmsScaleFactor; while (begin_src_ptr < end_src_ptr) { tmp = (zero_off - *begin_src_ptr); vrms += tmp * tmp; - begin_src_ptr += _channel_num; + begin_src_ptr++; } - vrms = vrms_pre + vrms / get_sample_count(); + vrms = vrms_pre + vrms / _sample_count; vrms_pre = vrms; } vrms = pow(vrms, 0.5); @@ -393,22 +428,20 @@ double DsoSnapshot::cal_vmean(int index) double vmean = 0; // Iterate through the samples to populate the first level mipmap - const uint8_t *const stop_src_ptr = (uint8_t*)_data + - get_sample_count() * _channel_num; - for (const uint8_t *src_ptr = (uint8_t*)_data + (index % _channel_num); - src_ptr < stop_src_ptr; src_ptr += VrmsScaleFactor * _channel_num) + const uint8_t *const stop_src_ptr = (uint8_t*)_ch_data[index] + _sample_count; + const uint8_t *src_ptr = (uint8_t*)_ch_data[index]; + + for (; src_ptr < stop_src_ptr; src_ptr += VrmsScaleFactor) { - const uint8_t * begin_src_ptr = - src_ptr; - const uint8_t *const end_src_ptr = - src_ptr + VrmsScaleFactor * _channel_num; + const uint8_t * begin_src_ptr = src_ptr; + const uint8_t *const end_src_ptr = src_ptr + VrmsScaleFactor; while (begin_src_ptr < end_src_ptr) { vmean += *begin_src_ptr; begin_src_ptr += _channel_num; } - vmean = vmean_pre + vmean / get_sample_count(); + vmean = vmean_pre + vmean / _sample_count; vmean_pre = vmean; } @@ -445,5 +478,18 @@ uint64_t DsoSnapshot::get_block_size(int block_index) } } +bool DsoSnapshot::get_max_min_value(uint8_t &maxv, uint8_t &minv) +{ + if (this->empty() == false){ + return false; + } + + return true; +} + +void* DsoSnapshot::get_data(){ + assert(0); +} + } // namespace data } // namespace pv diff --git a/DSView/pv/data/dsosnapshot.h b/DSView/pv/data/dsosnapshot.h index fb9b8fff..a37274e7 100644 --- a/DSView/pv/data/dsosnapshot.h +++ b/DSView/pv/data/dsosnapshot.h @@ -90,35 +90,36 @@ public: std::map ch_enable, bool instant); void append_payload(const sr_datafeed_dso &dso); - - const uint8_t* get_samples(int64_t start_sample, - int64_t end_sample, uint16_t index); + const uint8_t* get_samples(int64_t start_sample, int64_t end_sample, uint16_t index); void get_envelope_section(EnvelopeSection &s, uint64_t start, uint64_t end, float min_length, int probe_index); void enable_envelope(bool enable); - double cal_vrms(double zero_off, int index); double cal_vmean(int index); - bool has_data(int index); int get_block_num(); uint64_t get_block_size(int block_index); + bool get_max_min_value(uint8_t &maxv, uint8_t &minv); + void* get_data(); + private: void append_data(void *data, uint64_t samples, bool instant); void free_envelop(); void reallocate_envelope(Envelope &l); void append_payload_to_envelope_levels(bool header); + void free_data(); private: struct Envelope _envelope_levels[2*DS_MAX_DSO_PROBES_NUM][ScaleStepCount]; - bool _envelope_en; - bool _envelope_done; - bool _instant; - std::map _ch_enable; - + bool _envelope_en; + bool _envelope_done; + bool _instant; + std::map _ch_enable; + std::vector _ch_data; + friend class DsoSnapshotTest::Basic; }; diff --git a/DSView/pv/data/groupsnapshot.cpp b/DSView/pv/data/groupsnapshot.cpp index 46896f3d..69ba1b1f 100644 --- a/DSView/pv/data/groupsnapshot.cpp +++ b/DSView/pv/data/groupsnapshot.cpp @@ -53,7 +53,7 @@ GroupSnapshot::GroupSnapshot(const LogicSnapshot *_logic_snapshot, std::listget_data(); + // _data = logic_snapshot->get_data(); _sample_count = logic_snapshot->get_sample_count(); _unit_size = logic_snapshot->unit_size(); _index_list = index_list; diff --git a/DSView/pv/data/logicsnapshot.cpp b/DSView/pv/data/logicsnapshot.cpp index e5d7f5a8..1528ed68 100644 --- a/DSView/pv/data/logicsnapshot.cpp +++ b/DSView/pv/data/logicsnapshot.cpp @@ -92,7 +92,6 @@ void LogicSnapshot::init_all() _byte_fraction = 0; _ch_fraction = 0; _dest_ptr = NULL; - _data = NULL; _memory_failed = false; _last_ended = true; } @@ -220,6 +219,7 @@ void LogicSnapshot::append_cross_payload(const sr_datafeed_logic &logic) if (lbp == NULL) { _memory_failed = true; + dsv_err("LogicSnapshot::append_cross_payload, Malloc memory failed!"); return; } iter[index0].lbp[index1] = lbp; diff --git a/DSView/pv/data/snapshot.cpp b/DSView/pv/data/snapshot.cpp index a8d99d95..ec7be997 100644 --- a/DSView/pv/data/snapshot.cpp +++ b/DSView/pv/data/snapshot.cpp @@ -30,7 +30,6 @@ namespace pv { namespace data { Snapshot::Snapshot(int unit_size, uint64_t total_sample_count, unsigned int channel_num) : - _data(NULL), _capacity(0), _channel_num(channel_num), _sample_count(0), @@ -53,12 +52,8 @@ Snapshot::~Snapshot() void Snapshot::free_data() { - if (_data) { - free(_data); - _data = NULL; - _capacity = 0; - _sample_count = 0; - } + _capacity = 0; + _sample_count = 0; _ch_index.clear(); } diff --git a/DSView/pv/data/snapshot.h b/DSView/pv/data/snapshot.h index 31c576d7..f2309dcc 100644 --- a/DSView/pv/data/snapshot.h +++ b/DSView/pv/data/snapshot.h @@ -44,10 +44,6 @@ public: uint64_t get_ring_start(); uint64_t get_ring_end(); - inline const void* get_data(){ - return _data; - } - inline int unit_size(){ return _unit_size; } @@ -91,23 +87,20 @@ protected: uint64_t ring_end(); protected: - mutable std::mutex _mutex; - - - void* _data; + mutable std::mutex _mutex; mutable std::vector _ch_index; - uint64_t _capacity; + uint64_t _capacity; unsigned int _channel_num; - uint64_t _sample_count; - uint64_t _total_sample_count; - uint64_t _ring_sample_count; - int _unit_size; - uint8_t _unit_bytes; - uint16_t _unit_pitch; - bool _memory_failed; - bool _last_ended; - bool _have_data; + uint64_t _sample_count; + uint64_t _total_sample_count; + uint64_t _ring_sample_count; + int _unit_size; + uint8_t _unit_bytes; + uint16_t _unit_pitch; + bool _memory_failed; + bool _last_ended; + bool _have_data; }; } // namespace data diff --git a/DSView/pv/data/spectrumstack.cpp b/DSView/pv/data/spectrumstack.cpp index 724cceaa..f32861a5 100644 --- a/DSView/pv/data/spectrumstack.cpp +++ b/DSView/pv/data/spectrumstack.cpp @@ -204,9 +204,10 @@ void SpectrumStack::calc_fft() // prepare _xn data const int offset = dsoSig->get_hw_offset(); const double vscale = dsoSig->get_vDialValue() * dsoSig->get_factor() * DS_CONF_DSO_VDIVS / (1000*255.0); - const uint16_t step = _snapshot->get_channel_num() * _sample_interval; + const uint16_t step = _sample_interval; const uint8_t *const samples = _snapshot->get_samples(0, _sample_num*_sample_interval-1, _index); double wsum = 0; + for (unsigned int i = 0; i < _sample_num; i++) { double w = window(i, _windows_index); _xn[i] = (samples[i*step] - offset) * vscale * w; diff --git a/DSView/pv/dsvdef.h b/DSView/pv/dsvdef.h index dbcf7a7f..a684c5e1 100644 --- a/DSView/pv/dsvdef.h +++ b/DSView/pv/dsvdef.h @@ -52,6 +52,9 @@ enum View_type { #define ABS_VAL(x) ((x) > 0 ? (x) : -(x)) +#define SESSION_FORMAT_VERSION 3 +#define HEADER_FORMAT_VERSION 3 + namespace DecoderDataFormat { enum _data_format diff --git a/DSView/pv/mainwindow.cpp b/DSView/pv/mainwindow.cpp index 08819f18..3f76410c 100644 --- a/DSView/pv/mainwindow.cpp +++ b/DSView/pv/mainwindow.cpp @@ -98,8 +98,7 @@ #include "ZipMaker.h" #include "ui/langresource.h" #include "mainframe.h" - -#define BASE_SESSION_VERSION 3 +#include "dsvdef.h" namespace pv { @@ -631,7 +630,7 @@ namespace pv QString title = QApplication::applicationName() + " v" + QApplication::applicationVersion(); QJsonArray channelVar; - sessionVar["Version"] = QJsonValue::fromVariant(BASE_SESSION_VERSION); + sessionVar["Version"] = QJsonValue::fromVariant(SESSION_FORMAT_VERSION); sessionVar["Device"] = QJsonValue::fromVariant(_device_agent->driver_name()); sessionVar["DeviceMode"] = QJsonValue::fromVariant(_device_agent->get_work_mode()); sessionVar["Language"] = QJsonValue::fromVariant(app._frameOptions.language); diff --git a/DSView/pv/storesession.cpp b/DSView/pv/storesession.cpp index cc7f24aa..2bf4b993 100644 --- a/DSView/pv/storesession.cpp +++ b/DSView/pv/storesession.cpp @@ -209,118 +209,53 @@ bool StoreSession::save_start() return false; } -void StoreSession::save_proc(data::Snapshot *snapshot) +void StoreSession::save_logic(pv::data::LogicSnapshot *logic_snapshot) { - assert(snapshot); - char chunk_name[20] = {0}; - + uint16_t to_save_probes = 0; + bool sample; int ret = SR_ERR; - int num = 0; - data::LogicSnapshot *logic_snapshot = NULL; - //data::AnalogSnapshot *analog_snapshot = NULL; - //data::DsoSnapshot *dso_snapshot = NULL; + int num; - if ((logic_snapshot = dynamic_cast(snapshot))) { - uint16_t to_save_probes = 0; - for(auto s : _session->get_signals()) { - if (s->enabled() && logic_snapshot->has_data(s->get_index())) - to_save_probes++; - } - _unit_count = logic_snapshot->get_sample_count() / 8 * to_save_probes; - num = logic_snapshot->get_block_num(); - bool sample; - - for(auto s : _session->get_signals()) { - int ch_type = s->get_type(); - if (ch_type == SR_CHANNEL_LOGIC) { - int ch_index = s->get_index(); - if (!s->enabled() || !logic_snapshot->has_data(ch_index)) - continue; - for (int i = 0; !_canceled && i < num; i++) { - uint8_t *buf = logic_snapshot->get_block_buf(i, ch_index, sample); - uint64_t size = logic_snapshot->get_block_size(i); - bool need_malloc = (buf == NULL); - if (need_malloc) { - buf = (uint8_t *)malloc(size); - if (buf == NULL) { - _has_error = true; - _error = L_S(STR_PAGE_DLG, S_ID(IDS_MSG_STORESESS_SAVEPROC_ERROR1), - "Failed to create zip file. Malloc error."); - } else { - memset(buf, sample ? 0xff : 0x0, size); - } - } - - MakeChunkName(chunk_name, i, ch_index, ch_type, File_Version); - ret = m_zipDoc.AddFromBuffer(chunk_name, (const char*)buf, 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; - if (need_malloc) - free(buf); - progress_updated(); - } - } - } + for(auto s : _session->get_signals()) { + if (s->enabled() && logic_snapshot->has_data(s->get_index())) + to_save_probes++; } - else { - int ch_type = -1; - for(auto s : _session->get_signals()) { - ch_type = s->get_type(); - break; - } - if (ch_type != -1) { - num = snapshot->get_block_num(); - _unit_count = snapshot->get_sample_count() * - snapshot->get_unit_bytes() * - snapshot->get_channel_num(); - uint8_t *buf = (uint8_t *)snapshot->get_data() + - (snapshot->get_ring_start() * snapshot->get_unit_bytes() * snapshot->get_channel_num()); - const uint8_t *buf_start = (uint8_t *)snapshot->get_data(); - const uint8_t *buf_end = buf_start + _unit_count; + + _unit_count = logic_snapshot->get_sample_count() / 8 * to_save_probes; + num = logic_snapshot->get_block_num(); + + for(auto s : _session->get_signals()) + { + int ch_type = s->get_type(); + if (ch_type == SR_CHANNEL_LOGIC) { + int ch_index = s->get_index(); + if (!s->enabled() || !logic_snapshot->has_data(ch_index)) + continue; for (int i = 0; !_canceled && i < num; i++) { - const uint64_t size = snapshot->get_block_size(i); - if ((buf + size) > buf_end) { - uint8_t *tmp = (uint8_t *)malloc(size); - if (tmp == NULL) { + uint8_t *buf = logic_snapshot->get_block_buf(i, ch_index, sample); + uint64_t size = logic_snapshot->get_block_size(i); + bool need_malloc = (buf == NULL); + if (need_malloc) { + buf = (uint8_t *)malloc(size); + if (buf == NULL) { _has_error = true; _error = L_S(STR_PAGE_DLG, S_ID(IDS_MSG_STORESESS_SAVEPROC_ERROR1), - "Failed to create zip file. Malloc error."); + "Failed to create zip file. Malloc error."); } else { - memcpy(tmp, buf, buf_end-buf); - memcpy(tmp+(buf_end-buf), buf_start, buf+size-buf_end); - } - - MakeChunkName(chunk_name, i, 0, ch_type, File_Version); - ret = m_zipDoc.AddFromBuffer(chunk_name, (const char*)tmp, size) ? SR_OK : -1; - - buf += (size - _unit_count); - if (tmp) - free(tmp); - } else { - - MakeChunkName(chunk_name, i, 0, ch_type, File_Version); - ret = m_zipDoc.AddFromBuffer(chunk_name, (const char*)buf, size) ? SR_OK : -1; - - buf += size; + memset(buf, sample ? 0xff : 0x0, size); + } } + + MakeChunkName(chunk_name, i, ch_index, ch_type, HEADER_FORMAT_VERSION); + ret = m_zipDoc.AddFromBuffer(chunk_name, (const char*)buf, 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."); + "Failed to create zip file. Please check write permission of this path."); } progress_updated(); if (_has_error) @@ -328,14 +263,18 @@ void StoreSession::save_proc(data::Snapshot *snapshot) return; } _units_stored += size; + if (need_malloc) + free(buf); progress_updated(); } } } - progress_updated(); - if (_canceled || num == 0) + progress_updated(); + + if (_canceled || num == 0){ QFile::remove(_file_name); + } else { bool bret = m_zipDoc.Close(); m_zipDoc.Release(); @@ -347,6 +286,165 @@ void StoreSession::save_proc(data::Snapshot *snapshot) } } +void StoreSession::save_analog(pv::data::AnalogSnapshot *analog_snapshot) +{ + char chunk_name[20] = {0}; + int num; + int ret = SR_ERR; + + int ch_type = -1; + for(auto s : _session->get_signals()) { + ch_type = s->get_type(); + break; + } + + if (ch_type != -1) { + num = analog_snapshot->get_block_num(); + _unit_count = analog_snapshot->get_sample_count() * + analog_snapshot->get_unit_bytes() * + analog_snapshot->get_channel_num(); + uint8_t *buf = NULL; + uint8_t *buf_start = NULL; + + buf = (uint8_t *)analog_snapshot->get_data() + + (analog_snapshot->get_ring_start() * analog_snapshot->get_unit_bytes() + * analog_snapshot->get_channel_num()); + + buf_start = (uint8_t *)analog_snapshot->get_data(); + + const uint8_t *buf_end = buf_start + _unit_count; + + for (int i = 0; !_canceled && i < num; i++) { + const uint64_t size = analog_snapshot->get_block_size(i); + if ((buf + size) > buf_end) { + uint8_t *tmp = (uint8_t *)malloc(size); + if (tmp == NULL) { + _has_error = true; + _error = L_S(STR_PAGE_DLG, S_ID(IDS_MSG_STORESESS_SAVEPROC_ERROR1), + "Failed to create zip file. Malloc error."); + } else { + memcpy(tmp, buf, buf_end-buf); + memcpy(tmp+(buf_end-buf), buf_start, buf+size-buf_end); + } + + MakeChunkName(chunk_name, i, 0, ch_type, HEADER_FORMAT_VERSION); + ret = m_zipDoc.AddFromBuffer(chunk_name, (const char*)tmp, size) ? SR_OK : -1; + + buf += (size - _unit_count); + if (tmp) + free(tmp); + } + else { + MakeChunkName(chunk_name, i, 0, ch_type, HEADER_FORMAT_VERSION); + ret = m_zipDoc.AddFromBuffer(chunk_name, (const char*)buf, size) ? SR_OK : -1; + + buf += size; + } + + 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(); + } + } + + progress_updated(); + + if (_canceled || num == 0){ + QFile::remove(_file_name); + } + else { + bool bret = m_zipDoc.Close(); + m_zipDoc.Release(); + + if (!bret){ + _has_error = true; + _error = m_zipDoc.GetError(); + } + } +} + +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; + + 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(); + } + + progress_updated(); + + if (_canceled || size == 0){ + QFile::remove(_file_name); + } + else { + bool bret = m_zipDoc.Close(); + m_zipDoc.Release(); + + if (!bret){ + _has_error = true; + _error = m_zipDoc.GetError(); + } + } +} + +void StoreSession::save_proc(data::Snapshot *snapshot) +{ + assert(snapshot); + + data::LogicSnapshot *logic_snapshot = NULL; + data::AnalogSnapshot *analog_snapshot = NULL; + data::DsoSnapshot *dso_snapshot = NULL; + + if ((logic_snapshot = dynamic_cast(snapshot))) { + save_logic(logic_snapshot); + } + else if ((analog_snapshot = dynamic_cast(snapshot))) { + save_analog(analog_snapshot); + } + else if ((dso_snapshot = dynamic_cast(snapshot))) { + save_dso(dso_snapshot); + } +} + bool StoreSession::meta_gen(data::Snapshot *snapshot, std::string &str) { GSList *l; @@ -359,7 +457,7 @@ bool StoreSession::meta_gen(data::Snapshot *snapshot, std::string &str) char meta[300] = {0}; sprintf(meta, "%s", "[version]\n"); str += meta; - sprintf(meta, "version = %d\n", File_Version); str += meta; + sprintf(meta, "version = %d\n", HEADER_FORMAT_VERSION); str += meta; sprintf(meta, "%s", "[header]\n"); str += meta; int mode = _session->get_device()->get_work_mode(); @@ -815,17 +913,39 @@ void StoreSession::export_proc(data::Snapshot *snapshot) } } else if (channel_type == SR_CHANNEL_DSO) { - _unit_count = snapshot->get_sample_count(); - unsigned char* datat = (unsigned char*)snapshot->get_data(); + _unit_count = snapshot->get_sample_count(); unsigned int usize = 8192; unsigned int size = usize; struct sr_datafeed_dso dp; + uint8_t *ch_data_buffer = (uint8_t*)malloc(usize * dso_snapshot->get_channel_num() + 1); + if (ch_data_buffer == NULL){ + dsv_err("%s", "StoreSession::export_proc, malloc failed."); + return; + } + + int ch_num = dso_snapshot->get_channel_num(); + for(uint64_t i = 0; !_canceled && i < _unit_count; i+=usize){ if(_unit_count - i < usize) size = _unit_count - i; - dp.data = &datat[i*snapshot->get_channel_num()]; + // Make the cross data buffer. + for (int ch=0; chget_samples(0,0, ch) + i; + const uint8_t *rd_end = rd + size; + + while (rd < rd_end) + { + *wr = *rd; + wr += ch_num; + rd++; + } + } + + dp.data = ch_data_buffer; dp.num_samples = size; p.type = SR_DF_DSO; p.status = SR_PKT_OK; @@ -842,9 +962,14 @@ void StoreSession::export_proc(data::Snapshot *snapshot) progress_updated(); } + if (ch_data_buffer){ + free(ch_data_buffer); + ch_data_buffer = NULL; + } + } else if (channel_type == SR_CHANNEL_ANALOG) { _unit_count = snapshot->get_sample_count(); - unsigned char* datat = (unsigned char*)snapshot->get_data(); + unsigned char* datat = (unsigned char*)analog_snapshot->get_data(); unsigned int usize = 8192; unsigned int size = usize; struct sr_datafeed_analog ap; @@ -1364,7 +1489,7 @@ void StoreSession::MakeChunkName(char *chunk_name, int chunk_num, int index, int { chunk_name[0] = 0; - if (version == 2) + if (version >= 2) { const char *type_name = NULL; type_name = (type == SR_CHANNEL_LOGIC) ? "L" : (type == SR_CHANNEL_DSO) ? "O" diff --git a/DSView/pv/storesession.h b/DSView/pv/storesession.h index 529d5469..b95358ec 100644 --- a/DSView/pv/storesession.h +++ b/DSView/pv/storesession.h @@ -39,6 +39,9 @@ class SigSession; namespace data { class Snapshot; +class LogicSnapshot; +class AnalogSnapshot; +class DsoSnapshot; } namespace dock { @@ -48,10 +51,7 @@ class ProtocolDock; class StoreSession : public QObject { Q_OBJECT - -private: - const static int File_Version = 2; - + public: StoreSession(SigSession *session); @@ -73,6 +73,9 @@ public: private: void save_proc(pv::data::Snapshot *snapshot); + void save_logic(pv::data::LogicSnapshot *logic_snapshot); + void save_analog(pv::data::AnalogSnapshot *analog_snapshot); + void save_dso(pv::data::DsoSnapshot *dso_snapshot); bool meta_gen(data::Snapshot *snapshot, std::string &str); void export_proc(pv::data::Snapshot *snapshot); bool decoders_gen(std::string &str); diff --git a/DSView/pv/toolbars/filebar.cpp b/DSView/pv/toolbars/filebar.cpp index 909f1e74..526464f2 100644 --- a/DSView/pv/toolbars/filebar.cpp +++ b/DSView/pv/toolbars/filebar.cpp @@ -38,7 +38,8 @@ namespace toolbars { FileBar::FileBar(SigSession *session, QWidget *parent) : QToolBar("File Bar", parent), _session(session), - _file_button(this) + _file_button(this), + _cvt_button(this) { setMovable(false); setContentsMargins(0,0,0,0); @@ -83,6 +84,12 @@ FileBar::FileBar(SigSession *session, QWidget *parent) : _file_button.setMenu(_menu); addWidget(&_file_button); + + _cvt_button.setToolButtonStyle(Qt::ToolButtonTextUnderIcon); + _cvt_action = addWidget(&_cvt_button); + _cvt_button.setObjectName(QString::fromUtf8("menuSession")); + //_cvt_action->setVisible(false); + retranslateUi(); connect(_action_load, SIGNAL(triggered()), this, SLOT(on_actionLoad_triggered())); @@ -116,6 +123,7 @@ void FileBar::retranslateUi() _action_save->setText(L_S(STR_PAGE_TOOLBAR, S_ID(IDS_FILEBAR_SAVE), "&Save...")); _action_export->setText(L_S(STR_PAGE_TOOLBAR, S_ID(IDS_FILEBAR_EXPORT), "&Export...")); _action_capture->setText(L_S(STR_PAGE_TOOLBAR, S_ID(IDS_FILEBAR_CAPTURE), "&Capture...")); + _cvt_button.setText(L_S(STR_PAGE_TOOLBAR, S_ID(IDS_FILEBAR_CONVERT_LOGIC), "Lo&gic")); } void FileBar::reStyle() @@ -131,6 +139,7 @@ void FileBar::reStyle() _action_export->setIcon(QIcon(iconPath+"/export.svg")); _action_capture->setIcon(QIcon(iconPath+"/capture.svg")); _file_button.setIcon(QIcon(iconPath+"/file.svg")); + _cvt_button.setIcon(QIcon(iconPath+"/la.svg")); } void FileBar::on_actionOpen_triggered() diff --git a/DSView/pv/toolbars/filebar.h b/DSView/pv/toolbars/filebar.h index af758f65..8463d6cc 100644 --- a/DSView/pv/toolbars/filebar.h +++ b/DSView/pv/toolbars/filebar.h @@ -68,6 +68,8 @@ private: SigSession* _session; QToolButton _file_button; + QToolButton _cvt_button; + QAction *_cvt_action; QMenu *_menu; QMenu *_menu_session; //when the hardware device is connected,it will be enable QAction *_action_load; diff --git a/DSView/pv/view/dsosignal.cpp b/DSView/pv/view/dsosignal.cpp index f7144432..e4b68655 100644 --- a/DSView/pv/view/dsosignal.cpp +++ b/DSView/pv/view/dsosignal.cpp @@ -729,9 +729,7 @@ void DsoSignal::paint_prepare() return; if (!snapshot->has_data(get_index())) - return; - - const uint16_t enabled_channels = snapshot->get_channel_num(); + return; if (session->trigd()) { if (get_index() == session->trigd_ch()) { @@ -747,8 +745,8 @@ void DsoSignal::paint_prepare() return; const uint8_t *const trig_samples = snapshot->get_samples(0, 0, get_index()); for (uint16_t i = 0; i < TrigHRng; i++) { - const int64_t i0 = (trig_index - i - 1)*enabled_channels; - const int64_t i1 = (trig_index - i)*enabled_channels; + const int64_t i0 = trig_index - i - 1; + const int64_t i1 = trig_index - i; if (i1 < 0) break; const uint8_t t0 = trig_samples[i0]; @@ -761,8 +759,6 @@ void DsoSignal::paint_prepare() } } } - //if (_view->trig_hoff() == 0 && trig_samples[3] != _trig_value) - // _view->set_trig_hoff(0); } else { _view->set_trig_hoff(0); } @@ -1053,9 +1049,8 @@ void DsoSignal::paint_trace(QPainter &p, if (sample_count > 0) { pv::data::DsoSnapshot *pshot = const_cast(snapshot); - auto pdata = pshot->get_samples(start, end, get_index()); - const uint8_t *const samples = pdata; - assert(samples); + const uint8_t *const samples_buffer = pshot->get_samples(start, end, get_index());; + assert(samples_buffer); QColor trace_colour = _colour; trace_colour.setAlpha(View::ForeAlpha); @@ -1066,19 +1061,21 @@ void DsoSignal::paint_trace(QPainter &p, float top = get_view_rect().top(); float bottom = get_view_rect().bottom(); + float right = (float)get_view_rect().right(); double pixels_per_sample = 1.0/samples_per_pixel; - uint8_t value; - int64_t sample_end = sample_count*num_channels; + uint8_t value; float x = (start / samples_per_pixel - pixels_offset) + left + _view->trig_hoff()*pixels_per_sample; - for (int64_t sample = 0; sample < sample_end; sample+=num_channels) { - value = samples[sample]; - const float y = min(max(top, zeroY + (value - hw_offset) * _scale), bottom); - if (x > get_view_rect().right()) { + float y; + + for (int64_t sample = 0; sample < sample_count; sample++) { + value = samples_buffer[sample]; + y = min(max(top, zeroY + (value - hw_offset) * _scale), bottom); + if (x > right) { point--; - const float lastY = point->y() + (y - point->y()) / (x - point->x()) * (get_view_rect().right() - point->x()); + const float lastY = point->y() + (y - point->y()) / (x - point->x()) * (right - point->x()); point++; - *point++ = QPointF(get_view_rect().right(), lastY); + *point++ = QPointF(right, lastY); break; } *point++ = QPointF(x, y); diff --git a/DSView/pv/view/lissajoustrace.cpp b/DSView/pv/view/lissajoustrace.cpp index 3e56392a..0b43d798 100644 --- a/DSView/pv/view/lissajoustrace.cpp +++ b/DSView/pv/view/lissajoustrace.cpp @@ -171,11 +171,10 @@ void LissajousTrace::paint_mid(QPainter &p, int left, int right, QColor fore, QC const uint8_t *const samples = snapshot->get_samples(0, sample_count-1, 0); for (uint64_t i = 0; i < sample_count; i++) { - *point++ = QPointF(left + samples[i*channel_num + _xIndex] * scale, - bottom - samples[i*channel_num + _yIndex] * scale); + *point++ = QPointF(left + samples[i + _xIndex] * scale, + bottom - samples[i + _yIndex] * scale); } p.setPen(view::View::Blue); - //p.drawPoints(points, sample_count); p.drawPolyline(points, point - points); delete[] points; } diff --git a/lang/cn/toolbar.json b/lang/cn/toolbar.json index 98bcb191..62b24246 100644 --- a/lang/cn/toolbar.json +++ b/lang/cn/toolbar.json @@ -133,8 +133,10 @@ "id": "IDS_FILEBAR_CAPTURE", "text": "截屏(&C)" }, - - + { + "id": "IDS_FILEBAR_CONVERT_LOGIC", + "text": "逻辑分析(&G)" + }, { "id": "IDS_LOGOBAR_HELP", "text": "帮助" diff --git a/lang/en/toolbar.json b/lang/en/toolbar.json index 290287ad..77d9b11d 100644 --- a/lang/en/toolbar.json +++ b/lang/en/toolbar.json @@ -133,8 +133,10 @@ "id": "IDS_FILEBAR_CAPTURE", "text": "&Capture..." }, - - + { + "id": "IDS_FILEBAR_CONVERT_LOGIC", + "text": "Lo&gic" + }, { "id": "IDS_LOGOBAR_HELP", "text": "Help" diff --git a/libsigrok4DSL/session_driver.c b/libsigrok4DSL/session_driver.c index 8594a68e..c3407660 100644 --- a/libsigrok4DSL/session_driver.c +++ b/libsigrok4DSL/session_driver.c @@ -106,7 +106,6 @@ struct session_vdev void *buf; void *logic_buf; - int64_t bytes_read; int cur_channel; int cur_block; int num_blocks; @@ -277,7 +276,7 @@ static int receive_data(int fd, int revents, const struct sr_dev_inst *sdi) return FALSE; } } - else if (vdev->version == 2) + else if (vdev->version > 1) { channel = vdev->cur_channel; pl = sdi->channels; @@ -299,13 +298,13 @@ static int receive_data(int fd, int revents, const struct sr_dev_inst *sdi) if (unzLocateFile(vdev->archive, file_name, 0) != UNZ_OK) { - sr_err("cant't locate zip inner file:%s", file_name); + sr_err("cant't locate zip inner file:\"%s\"", file_name); send_error_packet(sdi, vdev, &packet); return FALSE; } if (unzOpenCurrentFile(vdev->archive) != UNZ_OK) { - sr_err("cant't open zip inner file:%s", file_name); + sr_err("cant't open zip inner file:\"%s\"", file_name); send_error_packet(sdi, vdev, &packet); return FALSE; } @@ -318,7 +317,7 @@ static int receive_data(int fd, int revents, const struct sr_dev_inst *sdi) if (-1 == ret) { - sr_err("read zip inner file error:%s", file_name); + sr_err("read zip inner file error:\"%s\"", file_name); send_error_packet(sdi, vdev, &packet); return FALSE; } @@ -350,9 +349,10 @@ static int receive_data(int fd, int revents, const struct sr_dev_inst *sdi) analog.mqflags = SR_MQFLAG_AC; analog.data = vdev->buf; } - else - { - if (vdev->version == 2){ + else if (sdi->mode == LOGIC) + { + // Only supports version 1 file. + if (vdev->version > 1){ assert(0); } @@ -366,13 +366,11 @@ static int receive_data(int fd, int revents, const struct sr_dev_inst *sdi) logic.index = 0; logic.order = vdev->cur_channel; - //version == 1 logic.length = ret / 16 * vdev->enabled_probes; logic.data = vdev->logic_buf; trans_data(sdi); } - vdev->bytes_read += ret; ds_data_forward(sdi, &packet); } else @@ -385,7 +383,7 @@ static int receive_data(int fd, int revents, const struct sr_dev_inst *sdi) { vdev->cur_channel++; } - else if (vdev->version == 2) + else if (vdev->version > 1) { vdev->cur_block++; // if read to the last block, move to next channel @@ -408,20 +406,18 @@ static int receive_data(int fd, int revents, const struct sr_dev_inst *sdi) { // abort close_archive(vdev); - vdev->bytes_read = 0; } } return TRUE; } -static int receive_data_logic2(int fd, int revents, const struct sr_dev_inst *sdi) +static int receive_data_logic_dso_v2(int fd, int revents, const struct sr_dev_inst *sdi) { struct session_vdev *vdev = NULL; struct sr_datafeed_packet packet; struct sr_datafeed_logic logic; struct sr_datafeed_dso dso; - struct sr_datafeed_analog analog; GSList *l; int ret; char file_name[32]; @@ -434,8 +430,9 @@ static int receive_data_logic2(int fd, int revents, const struct sr_dev_inst *sd int bToEnd; int chIndex; int chan_num; - void *p_wr; - void *p_rd; + uint8_t *p_wr; + uint8_t *p_rd; + int byte_align; assert(sdi); assert(sdi->priv); @@ -455,12 +452,18 @@ static int receive_data_logic2(int fd, int revents, const struct sr_dev_inst *sd assert(vdev->archive); chan_num = vdev->num_probes; + byte_align = sdi->mode == LOGIC ? 8 : 1; if (chan_num < 1){ sr_err("%s: channel count < 1.", __func__); return SR_ERR_ARG; - } + } + if (chan_num > SESSION_MAX_CHANNEL_COUNT){ + sr_err("%s: channel count is to big.", __func__); + return SR_ERR_ARG; + } + // Make buffer if (vdev->packet_buffer == NULL){ vdev->cur_block = 0; @@ -470,12 +473,16 @@ static int receive_data_logic2(int fd, int revents, const struct sr_dev_inst *sd return SR_ERR_MALLOC; } - for (ch_index = 0; ch_index < SESSION_MAX_CHANNEL_COUNT; ch_index++){ + for (ch_index = 0; ch_index <= chan_num; ch_index++){ vdev->packet_buffer->block_bufs[ch_index] = NULL; vdev->packet_buffer->block_read_positions[ch_index] = 0; } - vdev->packet_buffer->post_buf_len = 8 * chan_num * 1000; + if (sdi->mode == LOGIC) + vdev->packet_buffer->post_buf_len = 8 * chan_num * 1000; + else + vdev->packet_buffer->post_buf_len = chan_num * 1000; + vdev->packet_buffer->post_buf = g_try_malloc0(vdev->packet_buffer->post_buf_len + 1); if (vdev->packet_buffer->post_buf == NULL){ sr_err("%s: vdev->packet_buffer->post_buf malloc failed", __func__); @@ -504,12 +511,16 @@ static int receive_data_logic2(int fd, int revents, const struct sr_dev_inst *sd for (ch_index = 0; ch_index < chan_num; ch_index++) { - snprintf(file_name, sizeof(file_name)-1, "%s-%d/%d", "L", - ch_index, vdev->cur_block); + 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); + } if (unzLocateFile(vdev->archive, file_name, 0) != UNZ_OK) { - sr_err("cant't locate zip inner file:%s", file_name); + sr_err("cant't locate zip inner file:\"%s\"", file_name); send_error_packet(sdi, vdev, &packet); return FALSE; } @@ -525,9 +536,9 @@ static int receive_data_logic2(int fd, int revents, const struct sr_dev_inst *sd if (ch_index == 0){ pack_buffer->block_data_len = fileInfo.uncompressed_size; - if (pack_buffer->block_data_len > pack_buffer->block_buf_len){ - for (ch_index2 = 0; ch_index2 < chan_num; ch_index2++) - { + if (pack_buffer->block_data_len > pack_buffer->block_buf_len) + { + for (ch_index2 = 0; ch_index2 < chan_num; ch_index2++){ // Release the old buffer. if (pack_buffer->block_bufs[ch_index2] != NULL){ g_free(pack_buffer->block_bufs[ch_index2]); @@ -556,7 +567,7 @@ static int receive_data_logic2(int fd, int revents, const struct sr_dev_inst *sd // Read the data to buffer. if (unzOpenCurrentFile(vdev->archive) != UNZ_OK) { - sr_err("cant't open zip inner file:%s", file_name); + sr_err("cant't open zip inner file:\"%s\"", file_name); send_error_packet(sdi, vdev, &packet); return FALSE; } @@ -564,7 +575,7 @@ static int receive_data_logic2(int fd, int revents, const struct sr_dev_inst *sd ret = unzReadCurrentFile(vdev->archive, pack_buffer->block_bufs[ch_index], pack_buffer->block_data_len); if (-1 == ret) { - sr_err("read zip inner file error:%s", file_name); + sr_err("read zip inner file error:\"%s\"", file_name); send_error_packet(sdi, vdev, &packet); return FALSE; } @@ -576,16 +587,16 @@ static int receive_data_logic2(int fd, int revents, const struct sr_dev_inst *sd pack_buffer->block_chan_read_pos = 0; } - p_wr = (pack_buffer->post_buf + pack_buffer->post_len); - p_rd = (pack_buffer->block_bufs[chIndex] + pack_buffer->block_read_positions[chIndex]); - *(uint8_t*)p_wr = *(uint8_t*)p_rd; + 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_wr = *p_rd; pack_buffer->post_len++; pack_buffer->block_read_positions[chIndex]++; - if (pack_buffer->block_read_positions[chIndex] % 8 == 0 + if (pack_buffer->block_read_positions[chIndex] % byte_align == 0 || pack_buffer->block_read_positions[chIndex] == pack_buffer->block_data_len) - { + { chIndex++; if (pack_buffer->block_read_positions[chIndex] == pack_buffer->block_data_len){ @@ -598,23 +609,34 @@ static int receive_data_logic2(int fd, int revents, const struct sr_dev_inst *sd if (chIndex == chan_num){ chIndex = 0; - pack_buffer->block_chan_read_pos += 8; + pack_buffer->block_chan_read_pos += byte_align; } } } - if (pack_buffer->post_len >= 8 * chan_num) + if (pack_buffer->post_len >= byte_align * chan_num) { - packet.type = SR_DF_LOGIC; - packet.payload = &logic; - logic.format = LA_CROSS_DATA; - logic.index = 0; - logic.order = 0; + if (sdi->mode == LOGIC) + { + packet.type = SR_DF_LOGIC; + packet.payload = &logic; + logic.format = LA_CROSS_DATA; + logic.index = 0; + logic.order = 0; + logic.length = pack_buffer->post_len; + logic.data = pack_buffer->post_buf; + } + else{ + packet.type = SR_DF_DSO; + packet.payload = &dso; + dso.probes = sdi->channels; + dso.mq = SR_MQ_VOLTAGE; + dso.unit = SR_UNIT_VOLT; + dso.mqflags = SR_MQFLAG_AC; + dso.num_samples = pack_buffer->post_len / chan_num; + dso.data = pack_buffer->post_buf; + } - logic.length = pack_buffer->post_len; - logic.data = pack_buffer->post_buf; - - vdev->bytes_read += ret; ds_data_forward(sdi, &packet); pack_buffer->post_len = 0; } @@ -625,12 +647,12 @@ static int receive_data_logic2(int fd, int revents, const struct sr_dev_inst *sd ds_data_forward(sdi, &packet); sr_session_source_remove(-1); close_archive(vdev); - vdev->bytes_read = 0; } return TRUE; } + /* driver callbacks */ static int dev_clear(void); @@ -737,6 +759,9 @@ static int dev_close(struct sr_dev_inst *sdi) g_free(pack_buf->block_bufs[i]); pack_buf->block_bufs[i] = NULL; } + else{ + break; + } } } @@ -1328,13 +1353,13 @@ static int dev_acquisition_start(struct sr_dev_inst *sdi, void *cb_data) { if (unzLocateFile(vdev->archive, "data", 0) != UNZ_OK) { - sr_err("cant't locate zip inner file:%s", "data"); + sr_err("cant't locate zip inner file:\"%s\"", "data"); close_archive(vdev); return SR_ERR; } if (unzOpenCurrentFile(vdev->archive) != UNZ_OK) { - sr_err("cant't open zip inner file:%s", "data"); + sr_err("cant't open zip inner file:\"%s\"", "data"); close_archive(vdev); return SR_ERR; } @@ -1373,8 +1398,9 @@ static int dev_acquisition_start(struct sr_dev_inst *sdi, void *cb_data) } /* freewheeling source */ - if (sdi->mode == LOGIC && vdev->version == 2){ - sr_session_source_add(-1, 0, 0, receive_data_logic2, sdi); + if ((sdi->mode == LOGIC && vdev->version > 1) + || (sdi->mode == DSO && vdev->version > 2)){ + sr_session_source_add(-1, 0, 0, receive_data_logic_dso_v2, sdi); } else{ sr_session_source_add(-1, 0, 0, receive_data, sdi); @@ -1590,6 +1616,7 @@ static int sr_load_virtual_device_session(struct sr_dev_inst *sdi) if (!strcmp(keys[j], "version")) { version = strtoull(val, NULL, 10); + sr_info("The 'header' file format version:%d", version); } } } @@ -1713,7 +1740,7 @@ static int sr_load_virtual_device_session(struct sr_dev_inst *sdi) sr_dev_probe_name_set(sdi, tmp_u64, val); sr_dev_probe_enable(sdi, tmp_u64, TRUE); } - else if (version == 2) + else if (version > 1) { channel_type = (mode == DSO) ? SR_CHANNEL_DSO : (mode == ANALOG) ? SR_CHANNEL_ANALOG : SR_CHANNEL_LOGIC;