From f3d66e52ed6b454ea7a0662d5e6367e230116a2b Mon Sep 17 00:00:00 2001 From: Joel Holdsworth Date: Sun, 30 Nov 2014 10:46:23 +0000 Subject: [PATCH] Snapshot: Renamed to Segment --- CMakeLists.txt | 6 +- pv/data/analog.cpp | 20 +-- pv/data/analog.hpp | 14 +-- .../{analogsnapshot.cpp => analogsegment.cpp} | 26 ++-- .../{analogsnapshot.hpp => analogsegment.hpp} | 12 +- pv/data/decoderstack.cpp | 34 ++--- pv/data/decoderstack.hpp | 4 +- pv/data/logic.cpp | 22 ++-- pv/data/logic.hpp | 14 +-- .../{logicsnapshot.cpp => logicsegment.cpp} | 36 +++--- .../{logicsnapshot.hpp => logicsegment.hpp} | 22 ++-- pv/data/{snapshot.cpp => segment.cpp} | 22 ++-- pv/data/{snapshot.hpp => segment.hpp} | 16 +-- pv/data/signaldata.hpp | 4 +- pv/session.cpp | 62 ++++----- pv/session.hpp | 10 +- pv/storesession.cpp | 30 ++--- pv/storesession.hpp | 4 +- pv/view/analogsignal.cpp | 36 +++--- pv/view/analogsignal.hpp | 6 +- pv/view/decodetrace.cpp | 14 +-- pv/view/logicsignal.cpp | 20 +-- pv/view/view.cpp | 16 +-- test/CMakeLists.txt | 10 +- .../{analogsnapshot.cpp => analogsegment.cpp} | 36 +++--- .../{logicsnapshot.cpp => logicsegment.cpp} | 118 +++++++++--------- 26 files changed, 307 insertions(+), 307 deletions(-) rename pv/data/{analogsnapshot.cpp => analogsegment.cpp} (88%) rename pv/data/{analogsnapshot.hpp => analogsegment.hpp} (89%) rename pv/data/{logicsnapshot.cpp => logicsegment.cpp} (91%) rename pv/data/{logicsnapshot.hpp => logicsegment.hpp} (85%) rename pv/data/{snapshot.cpp => segment.cpp} (81%) rename pv/data/{snapshot.hpp => segment.hpp} (84%) rename test/data/{analogsnapshot.cpp => analogsegment.cpp} (72%) rename test/data/{logicsnapshot.cpp => logicsegment.cpp} (81%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 40878efa..de264c5a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -147,11 +147,11 @@ set(pulseview_SOURCES pv/storesession.cpp pv/util.cpp pv/data/analog.cpp - pv/data/analogsnapshot.cpp + pv/data/analogsegment.cpp pv/data/logic.cpp - pv/data/logicsnapshot.cpp + pv/data/logicsegment.cpp pv/data/signaldata.cpp - pv/data/snapshot.cpp + pv/data/segment.cpp pv/dialogs/about.cpp pv/dialogs/connect.cpp pv/dialogs/storeprogress.cpp diff --git a/pv/data/analog.cpp b/pv/data/analog.cpp index 3f96dae1..c95fffaf 100644 --- a/pv/data/analog.cpp +++ b/pv/data/analog.cpp @@ -21,7 +21,7 @@ #include #include "analog.hpp" -#include "analogsnapshot.hpp" +#include "analogsegment.hpp" using std::deque; using std::max; @@ -36,31 +36,31 @@ Analog::Analog() : { } -void Analog::push_snapshot(shared_ptr &snapshot) +void Analog::push_segment(shared_ptr &segment) { - snapshots_.push_front(snapshot); + segments_.push_front(segment); } -const deque< shared_ptr >& Analog::analog_snapshots() const +const deque< shared_ptr >& Analog::analog_segments() const { - return snapshots_; + return segments_; } -vector< shared_ptr > Analog::snapshots() const +vector< shared_ptr > Analog::segments() const { - return vector< shared_ptr >( - snapshots_.begin(), snapshots_.end()); + return vector< shared_ptr >( + segments_.begin(), segments_.end()); } void Analog::clear() { - snapshots_.clear(); + segments_.clear(); } uint64_t Analog::get_max_sample_count() const { uint64_t l = 0; - for (const std::shared_ptr s : snapshots_) { + for (const std::shared_ptr s : segments_) { assert(s); l = max(l, s->get_sample_count()); } diff --git a/pv/data/analog.hpp b/pv/data/analog.hpp index 9551afff..2fe588e4 100644 --- a/pv/data/analog.hpp +++ b/pv/data/analog.hpp @@ -29,27 +29,27 @@ namespace pv { namespace data { -class AnalogSnapshot; +class AnalogSegment; class Analog : public SignalData { public: Analog(); - void push_snapshot( - std::shared_ptr &snapshot); + void push_segment( + std::shared_ptr &segment); - const std::deque< std::shared_ptr >& - analog_snapshots() const; + const std::deque< std::shared_ptr >& + analog_segments() const; - std::vector< std::shared_ptr > snapshots() const; + std::vector< std::shared_ptr > segments() const; void clear(); uint64_t get_max_sample_count() const; private: - std::deque< std::shared_ptr > snapshots_; + std::deque< std::shared_ptr > segments_; }; } // namespace data diff --git a/pv/data/analogsnapshot.cpp b/pv/data/analogsegment.cpp similarity index 88% rename from pv/data/analogsnapshot.cpp rename to pv/data/analogsegment.cpp index 5e995158..b970bebd 100644 --- a/pv/data/analogsnapshot.cpp +++ b/pv/data/analogsegment.cpp @@ -27,7 +27,7 @@ #include -#include "analogsnapshot.hpp" +#include "analogsegment.hpp" using std::lock_guard; using std::recursive_mutex; @@ -39,15 +39,15 @@ using std::min_element; namespace pv { namespace data { -const int AnalogSnapshot::EnvelopeScalePower = 4; -const int AnalogSnapshot::EnvelopeScaleFactor = 1 << EnvelopeScalePower; -const float AnalogSnapshot::LogEnvelopeScaleFactor = +const int AnalogSegment::EnvelopeScalePower = 4; +const int AnalogSegment::EnvelopeScaleFactor = 1 << EnvelopeScalePower; +const float AnalogSegment::LogEnvelopeScaleFactor = logf(EnvelopeScaleFactor); -const uint64_t AnalogSnapshot::EnvelopeDataUnit = 64*1024; // bytes +const uint64_t AnalogSegment::EnvelopeDataUnit = 64*1024; // bytes -AnalogSnapshot::AnalogSnapshot( +AnalogSegment::AnalogSegment( uint64_t samplerate, const uint64_t expected_num_samples) : - Snapshot(samplerate, sizeof(float)) + Segment(samplerate, sizeof(float)) { set_capacity(expected_num_samples); @@ -55,14 +55,14 @@ AnalogSnapshot::AnalogSnapshot( memset(envelope_levels_, 0, sizeof(envelope_levels_)); } -AnalogSnapshot::~AnalogSnapshot() +AnalogSegment::~AnalogSegment() { lock_guard lock(mutex_); for (Envelope &e : envelope_levels_) free(e.samples); } -void AnalogSnapshot::append_interleaved_samples(const float *data, +void AnalogSegment::append_interleaved_samples(const float *data, size_t sample_count, size_t stride) { assert(unit_size_ == sizeof(float)); @@ -85,7 +85,7 @@ void AnalogSnapshot::append_interleaved_samples(const float *data, append_payload_to_envelope_levels(); } -const float* AnalogSnapshot::get_samples( +const float* AnalogSegment::get_samples( int64_t start_sample, int64_t end_sample) const { assert(start_sample >= 0); @@ -102,7 +102,7 @@ const float* AnalogSnapshot::get_samples( return data; } -void AnalogSnapshot::get_envelope_section(EnvelopeSection &s, +void AnalogSegment::get_envelope_section(EnvelopeSection &s, uint64_t start, uint64_t end, float min_length) const { assert(end <= get_sample_count()); @@ -126,7 +126,7 @@ void AnalogSnapshot::get_envelope_section(EnvelopeSection &s, s.length * sizeof(EnvelopeSample)); } -void AnalogSnapshot::reallocate_envelope(Envelope &e) +void AnalogSegment::reallocate_envelope(Envelope &e) { const uint64_t new_data_length = ((e.length + EnvelopeDataUnit - 1) / EnvelopeDataUnit) * EnvelopeDataUnit; @@ -138,7 +138,7 @@ void AnalogSnapshot::reallocate_envelope(Envelope &e) } } -void AnalogSnapshot::append_payload_to_envelope_levels() +void AnalogSegment::append_payload_to_envelope_levels() { Envelope &e0 = envelope_levels_[0]; uint64_t prev_length; diff --git a/pv/data/analogsnapshot.hpp b/pv/data/analogsegment.hpp similarity index 89% rename from pv/data/analogsnapshot.hpp rename to pv/data/analogsegment.hpp index 69c28a2a..38922f59 100644 --- a/pv/data/analogsnapshot.hpp +++ b/pv/data/analogsegment.hpp @@ -21,19 +21,19 @@ #ifndef PULSEVIEW_PV_DATA_ANALOGSNAPSHOT_H #define PULSEVIEW_PV_DATA_ANALOGSNAPSHOT_H -#include "snapshot.hpp" +#include "segment.hpp" #include #include -namespace AnalogSnapshotTest { +namespace AnalogSegmentTest { struct Basic; } namespace pv { namespace data { -class AnalogSnapshot : public Snapshot +class AnalogSegment : public Segment { public: struct EnvelopeSample @@ -66,9 +66,9 @@ private: static const uint64_t EnvelopeDataUnit; public: - AnalogSnapshot(uint64_t samplerate, uint64_t expected_num_samples = 0); + AnalogSegment(uint64_t samplerate, uint64_t expected_num_samples = 0); - virtual ~AnalogSnapshot(); + virtual ~AnalogSegment(); void append_interleaved_samples(const float *data, size_t sample_count, size_t stride); @@ -87,7 +87,7 @@ private: private: struct Envelope envelope_levels_[ScaleStepCount]; - friend struct AnalogSnapshotTest::Basic; + friend struct AnalogSegmentTest::Basic; }; } // namespace data diff --git a/pv/data/decoderstack.cpp b/pv/data/decoderstack.cpp index a764e452..e9876d21 100644 --- a/pv/data/decoderstack.cpp +++ b/pv/data/decoderstack.cpp @@ -27,7 +27,7 @@ #include "decoderstack.hpp" #include -#include +#include #include #include #include @@ -245,7 +245,7 @@ void DecoderStack::begin_decode() // We get the logic data of the first channel in the list. // This works because we are currently assuming all - // LogicSignals have the same data/snapshot + // LogicSignals have the same data/segment for (const shared_ptr &dec : stack_) if (dec && !dec->channels().empty() && ((logic_signal = (*dec->channels().begin()).second)) && @@ -255,16 +255,16 @@ void DecoderStack::begin_decode() if (!data) return; - // Check we have a snapshot of data - const deque< shared_ptr > &snapshots = - data->logic_snapshots(); - if (snapshots.empty()) + // Check we have a segment of data + const deque< shared_ptr > &segments = + data->logic_segments(); + if (segments.empty()) return; - snapshot_ = snapshots.front(); + segment_ = segments.front(); // Get the samplerate and start time - start_time_ = snapshot_->start_time(); - samplerate_ = snapshot_->samplerate(); + start_time_ = segment_->start_time(); + samplerate_ = segment_->samplerate(); if (samplerate_ == 0.0) samplerate_ = 1.0; @@ -301,7 +301,7 @@ void DecoderStack::decode_data( uint8_t chunk[DecodeChunkLength]; const unsigned int chunk_sample_count = - DecodeChunkLength / snapshot_->unit_size(); + DecodeChunkLength / segment_->unit_size(); for (int64_t i = 0; !interrupt_ && i < sample_count; i += chunk_sample_count) @@ -310,7 +310,7 @@ void DecoderStack::decode_data( const int64_t chunk_end = min( i + chunk_sample_count, sample_count); - snapshot_->get_samples(chunk, i, chunk_end); + segment_->get_samples(chunk, i, chunk_end); if (srd_session_send(session, i, i + sample_count, chunk, (chunk_end - i) * unit_size) != SRD_OK) { @@ -336,14 +336,14 @@ void DecoderStack::decode_proc() srd_session *session; srd_decoder_inst *prev_di = NULL; - assert(snapshot_); + assert(segment_); // Create the session srd_session_new(&session); assert(session); // Create the decoders - const unsigned int unit_size = snapshot_->unit_size(); + const unsigned int unit_size = segment_->unit_size(); for (const shared_ptr &dec : stack_) { @@ -365,7 +365,7 @@ void DecoderStack::decode_proc() // Get the intial sample count { unique_lock input_lock(input_mutex_); - sample_count = sample_count_ = snapshot_->get_sample_count(); + sample_count = sample_count_ = segment_->get_sample_count(); } // Start the session @@ -436,8 +436,8 @@ void DecoderStack::on_data_received() { { unique_lock lock(input_mutex_); - if (snapshot_) - sample_count_ = snapshot_->get_sample_count(); + if (segment_) + sample_count_ = segment_->get_sample_count(); } input_cond_.notify_one(); } @@ -446,7 +446,7 @@ void DecoderStack::on_frame_ended() { { unique_lock lock(input_mutex_); - if (snapshot_) + if (segment_) frame_complete_ = true; } input_cond_.notify_one(); diff --git a/pv/data/decoderstack.hpp b/pv/data/decoderstack.hpp index 39e507e8..38310990 100644 --- a/pv/data/decoderstack.hpp +++ b/pv/data/decoderstack.hpp @@ -58,7 +58,7 @@ class LogicSignal; namespace data { -class LogicSnapshot; +class LogicSegment; namespace decode { class Annotation; @@ -148,7 +148,7 @@ private: std::list< std::shared_ptr > stack_; - std::shared_ptr snapshot_; + std::shared_ptr segment_; mutable std::mutex input_mutex_; mutable std::condition_variable input_cond_; diff --git a/pv/data/logic.cpp b/pv/data/logic.cpp index 96f0d1fe..fe29aea4 100644 --- a/pv/data/logic.cpp +++ b/pv/data/logic.cpp @@ -21,7 +21,7 @@ #include #include "logic.hpp" -#include "logicsnapshot.hpp" +#include "logicsegment.hpp" using std::deque; using std::max; @@ -43,32 +43,32 @@ int Logic::get_num_channels() const return num_channels_; } -void Logic::push_snapshot( - shared_ptr &snapshot) +void Logic::push_segment( + shared_ptr &segment) { - snapshots_.push_front(snapshot); + segments_.push_front(segment); } -const deque< shared_ptr >& Logic::logic_snapshots() const +const deque< shared_ptr >& Logic::logic_segments() const { - return snapshots_; + return segments_; } -vector< shared_ptr > Logic::snapshots() const +vector< shared_ptr > Logic::segments() const { - return vector< shared_ptr >( - snapshots_.begin(), snapshots_.end()); + return vector< shared_ptr >( + segments_.begin(), segments_.end()); } void Logic::clear() { - snapshots_.clear(); + segments_.clear(); } uint64_t Logic::get_max_sample_count() const { uint64_t l = 0; - for (std::shared_ptr s : snapshots_) { + for (std::shared_ptr s : segments_) { assert(s); l = max(l, s->get_sample_count()); } diff --git a/pv/data/logic.hpp b/pv/data/logic.hpp index d57df0cf..9adc9750 100644 --- a/pv/data/logic.hpp +++ b/pv/data/logic.hpp @@ -28,7 +28,7 @@ namespace pv { namespace data { -class LogicSnapshot; +class LogicSegment; class Logic : public SignalData { @@ -37,13 +37,13 @@ public: int get_num_channels() const; - void push_snapshot( - std::shared_ptr &snapshot); + void push_segment( + std::shared_ptr &segment); - const std::deque< std::shared_ptr >& - logic_snapshots() const; + const std::deque< std::shared_ptr >& + logic_segments() const; - std::vector< std::shared_ptr > snapshots() const; + std::vector< std::shared_ptr > segments() const; void clear(); @@ -51,7 +51,7 @@ public: private: const unsigned int num_channels_; - std::deque< std::shared_ptr > snapshots_; + std::deque< std::shared_ptr > segments_; }; } // namespace data diff --git a/pv/data/logicsnapshot.cpp b/pv/data/logicsegment.cpp similarity index 91% rename from pv/data/logicsnapshot.cpp rename to pv/data/logicsegment.cpp index a89c8f93..2b9d89bf 100644 --- a/pv/data/logicsnapshot.cpp +++ b/pv/data/logicsegment.cpp @@ -25,7 +25,7 @@ #include #include -#include "logicsnapshot.hpp" +#include "logicsegment.hpp" #include @@ -41,14 +41,14 @@ using sigrok::Logic; namespace pv { namespace data { -const int LogicSnapshot::MipMapScalePower = 4; -const int LogicSnapshot::MipMapScaleFactor = 1 << MipMapScalePower; -const float LogicSnapshot::LogMipMapScaleFactor = logf(MipMapScaleFactor); -const uint64_t LogicSnapshot::MipMapDataUnit = 64*1024; // bytes +const int LogicSegment::MipMapScalePower = 4; +const int LogicSegment::MipMapScaleFactor = 1 << MipMapScalePower; +const float LogicSegment::LogMipMapScaleFactor = logf(MipMapScaleFactor); +const uint64_t LogicSegment::MipMapDataUnit = 64*1024; // bytes -LogicSnapshot::LogicSnapshot(shared_ptr logic, uint64_t samplerate, +LogicSegment::LogicSegment(shared_ptr logic, uint64_t samplerate, const uint64_t expected_num_samples) : - Snapshot(samplerate, logic->unit_size()), + Segment(samplerate, logic->unit_size()), last_append_sample_(0) { set_capacity(expected_num_samples); @@ -58,14 +58,14 @@ LogicSnapshot::LogicSnapshot(shared_ptr logic, uint64_t samplerate, append_payload(logic); } -LogicSnapshot::~LogicSnapshot() +LogicSegment::~LogicSegment() { lock_guard lock(mutex_); for (MipMapLevel &l : mip_map_) free(l.data); } -uint64_t LogicSnapshot::unpack_sample(const uint8_t *ptr) const +uint64_t LogicSegment::unpack_sample(const uint8_t *ptr) const { #ifdef HAVE_UNALIGNED_LITTLE_ENDIAN_ACCESS return *(uint64_t*)ptr; @@ -103,7 +103,7 @@ uint64_t LogicSnapshot::unpack_sample(const uint8_t *ptr) const #endif } -void LogicSnapshot::pack_sample(uint8_t *ptr, uint64_t value) +void LogicSegment::pack_sample(uint8_t *ptr, uint64_t value) { #ifdef HAVE_UNALIGNED_LITTLE_ENDIAN_ACCESS *(uint64_t*)ptr = value; @@ -139,7 +139,7 @@ void LogicSnapshot::pack_sample(uint8_t *ptr, uint64_t value) #endif } -void LogicSnapshot::append_payload(shared_ptr logic) +void LogicSegment::append_payload(shared_ptr logic) { assert(unit_size_ == logic->unit_size()); assert((logic->data_length() % unit_size_) == 0); @@ -153,7 +153,7 @@ void LogicSnapshot::append_payload(shared_ptr logic) append_payload_to_mipmap(); } -void LogicSnapshot::get_samples(uint8_t *const data, +void LogicSegment::get_samples(uint8_t *const data, int64_t start_sample, int64_t end_sample) const { assert(data); @@ -169,7 +169,7 @@ void LogicSnapshot::get_samples(uint8_t *const data, memcpy(data, (const uint8_t*)data_.data() + start_sample * unit_size_, size); } -void LogicSnapshot::reallocate_mipmap_level(MipMapLevel &m) +void LogicSegment::reallocate_mipmap_level(MipMapLevel &m) { const uint64_t new_data_length = ((m.length + MipMapDataUnit - 1) / MipMapDataUnit) * MipMapDataUnit; @@ -183,7 +183,7 @@ void LogicSnapshot::reallocate_mipmap_level(MipMapLevel &m) } } -void LogicSnapshot::append_payload_to_mipmap() +void LogicSegment::append_payload_to_mipmap() { MipMapLevel &m0 = mip_map_[0]; uint64_t prev_length; @@ -265,14 +265,14 @@ void LogicSnapshot::append_payload_to_mipmap() } } -uint64_t LogicSnapshot::get_sample(uint64_t index) const +uint64_t LogicSegment::get_sample(uint64_t index) const { assert(index < sample_count_); return unpack_sample((uint8_t*)data_.data() + index * unit_size_); } -void LogicSnapshot::get_subsampled_edges( +void LogicSegment::get_subsampled_edges( std::vector &edges, uint64_t start, uint64_t end, float min_length, int sig_index) @@ -451,7 +451,7 @@ void LogicSnapshot::get_subsampled_edges( edges.push_back(pair(end + 1, end_sample)); } -uint64_t LogicSnapshot::get_subsample(int level, uint64_t offset) const +uint64_t LogicSegment::get_subsample(int level, uint64_t offset) const { assert(level >= 0); assert(mip_map_[level].data); @@ -459,7 +459,7 @@ uint64_t LogicSnapshot::get_subsample(int level, uint64_t offset) const unit_size_ * offset); } -uint64_t LogicSnapshot::pow2_ceil(uint64_t x, unsigned int power) +uint64_t LogicSegment::pow2_ceil(uint64_t x, unsigned int power) { const uint64_t p = 1 << power; return (x + p - 1) / p * p; diff --git a/pv/data/logicsnapshot.hpp b/pv/data/logicsegment.hpp similarity index 85% rename from pv/data/logicsnapshot.hpp rename to pv/data/logicsegment.hpp index 8b1481ab..3e092c53 100644 --- a/pv/data/logicsnapshot.hpp +++ b/pv/data/logicsegment.hpp @@ -21,7 +21,7 @@ #ifndef PULSEVIEW_PV_DATA_LOGICSNAPSHOT_H #define PULSEVIEW_PV_DATA_LOGICSNAPSHOT_H -#include "snapshot.hpp" +#include "segment.hpp" #include #include @@ -30,7 +30,7 @@ namespace sigrok { class Logic; } -namespace LogicSnapshotTest { +namespace LogicSegmentTest { struct Pow2; struct Basic; struct LargeData; @@ -41,7 +41,7 @@ struct LongPulses; namespace pv { namespace data { -class LogicSnapshot : public Snapshot +class LogicSegment : public Segment { private: struct MipMapLevel @@ -62,10 +62,10 @@ public: typedef std::pair EdgePair; public: - LogicSnapshot(std::shared_ptr logic, + LogicSegment(std::shared_ptr logic, uint64_t samplerate, uint64_t expected_num_samples = 0); - virtual ~LogicSnapshot(); + virtual ~LogicSegment(); void append_payload(std::shared_ptr logic); @@ -84,7 +84,7 @@ private: public: /** - * Parses a logic data snapshot to generate a list of transitions + * Parses a logic data segment to generate a list of transitions * in a time interval to a given level of detail. * @param[out] edges The vector to place the edges into. * @param[in] start The start sample index. @@ -106,11 +106,11 @@ private: struct MipMapLevel mip_map_[ScaleStepCount]; uint64_t last_append_sample_; - friend struct LogicSnapshotTest::Pow2; - friend struct LogicSnapshotTest::Basic; - friend struct LogicSnapshotTest::LargeData; - friend struct LogicSnapshotTest::Pulses; - friend struct LogicSnapshotTest::LongPulses; + friend struct LogicSegmentTest::Pow2; + friend struct LogicSegmentTest::Basic; + friend struct LogicSegmentTest::LargeData; + friend struct LogicSegmentTest::Pulses; + friend struct LogicSegmentTest::LongPulses; }; } // namespace data diff --git a/pv/data/snapshot.cpp b/pv/data/segment.cpp similarity index 81% rename from pv/data/snapshot.cpp rename to pv/data/segment.cpp index 39fdc011..111b62b7 100644 --- a/pv/data/snapshot.cpp +++ b/pv/data/segment.cpp @@ -18,7 +18,7 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -#include "snapshot.hpp" +#include "segment.hpp" #include #include @@ -30,7 +30,7 @@ using std::recursive_mutex; namespace pv { namespace data { -Snapshot::Snapshot(uint64_t samplerate, unsigned int unit_size) : +Segment::Segment(uint64_t samplerate, unsigned int unit_size) : sample_count_(0), start_time_(0), samplerate_(samplerate), @@ -41,38 +41,38 @@ Snapshot::Snapshot(uint64_t samplerate, unsigned int unit_size) : assert(unit_size_ > 0); } -Snapshot::~Snapshot() +Segment::~Segment() { lock_guard lock(mutex_); } -uint64_t Snapshot::get_sample_count() const +uint64_t Segment::get_sample_count() const { lock_guard lock(mutex_); return sample_count_; } -double Snapshot::start_time() const +double Segment::start_time() const { return start_time_; } -double Snapshot::samplerate() const +double Segment::samplerate() const { return samplerate_; } -void Snapshot::set_samplerate(double samplerate) +void Segment::set_samplerate(double samplerate) { samplerate_ = samplerate; } -unsigned int Snapshot::unit_size() const +unsigned int Segment::unit_size() const { return unit_size_; } -void Snapshot::set_capacity(const uint64_t new_capacity) +void Segment::set_capacity(const uint64_t new_capacity) { lock_guard lock(mutex_); @@ -83,13 +83,13 @@ void Snapshot::set_capacity(const uint64_t new_capacity) } } -uint64_t Snapshot::capacity() const +uint64_t Segment::capacity() const { lock_guard lock(mutex_); return data_.size(); } -void Snapshot::append_data(void *data, uint64_t samples) +void Segment::append_data(void *data, uint64_t samples) { lock_guard lock(mutex_); diff --git a/pv/data/snapshot.hpp b/pv/data/segment.hpp similarity index 84% rename from pv/data/snapshot.hpp rename to pv/data/segment.hpp index 6015de9e..a754eab2 100644 --- a/pv/data/snapshot.hpp +++ b/pv/data/segment.hpp @@ -28,12 +28,12 @@ namespace pv { namespace data { -class Snapshot +class Segment { public: - Snapshot(uint64_t samplerate, unsigned int unit_size); + Segment(uint64_t samplerate, unsigned int unit_size); - virtual ~Snapshot(); + virtual ~Segment(); uint64_t get_sample_count() const; @@ -45,29 +45,29 @@ public: unsigned int unit_size() const; /** - * @brief Increase the capacity of the snapshot. + * @brief Increase the capacity of the segment. * * Increasing the capacity allows samples to be appended without needing * to reallocate memory. * * For the best efficiency @c set_capacity() should be called once before - * @c append_data() is called to set up the snapshot with the expected number + * @c append_data() is called to set up the segment with the expected number * of samples that will be appended in total. * * @note The capacity will automatically be increased when @c append_data() * is called if there is not enough capacity in the buffer to store the samples. * - * @param[in] new_capacity The new capacity of the snapshot. If this value is + * @param[in] new_capacity The new capacity of the segment. If this value is * smaller or equal than the current capacity then the method has no effect. */ void set_capacity(uint64_t new_capacity); /** - * @brief Get the current capacity of the snapshot. + * @brief Get the current capacity of the segment. * * The capacity can be increased by calling @c set_capacity(). * - * @return The current capacity of the snapshot. + * @return The current capacity of the segment. */ uint64_t capacity() const; diff --git a/pv/data/signaldata.hpp b/pv/data/signaldata.hpp index 51589771..c49cb5c0 100644 --- a/pv/data/signaldata.hpp +++ b/pv/data/signaldata.hpp @@ -28,7 +28,7 @@ namespace pv { namespace data { -class Snapshot; +class Segment; class SignalData { @@ -37,7 +37,7 @@ public: virtual ~SignalData() {} public: - virtual std::vector< std::shared_ptr > snapshots() const = 0; + virtual std::vector< std::shared_ptr > segments() const = 0; virtual void clear() = 0; diff --git a/pv/session.cpp b/pv/session.cpp index 46af90cc..7bb9de8d 100644 --- a/pv/session.cpp +++ b/pv/session.cpp @@ -27,10 +27,10 @@ #include "devicemanager.hpp" #include "data/analog.hpp" -#include "data/analogsnapshot.hpp" +#include "data/analogsegment.hpp" #include "data/decoderstack.hpp" #include "data/logic.hpp" -#include "data/logicsnapshot.hpp" +#include "data/logicsegment.hpp" #include "data/decode/decoder.hpp" #include "view/analogsignal.hpp" @@ -364,7 +364,7 @@ void Session::update_signals(shared_ptr device) [] (shared_ptr channel) { return channel->type() == ChannelType::LOGIC; }); - // Create data containers for the logic data snapshots + // Create data containers for the logic data segments { lock_guard data_lock(data_mutex_); @@ -460,7 +460,7 @@ void Session::sample_thread_proc(shared_ptr device, set_capture_state(Stopped); // Confirm that SR_DF_END was received - if (cur_logic_snapshot_) + if (cur_logic_segment_) { qDebug("SR_DF_END was not received."); assert(0); @@ -493,7 +493,7 @@ void Session::feed_in_meta(shared_ptr device, void Session::feed_in_frame_begin() { - if (cur_logic_snapshot_ || !cur_analog_snapshots_.empty()) + if (cur_logic_segment_ || !cur_analog_segments_.empty()) frame_began(); } @@ -507,7 +507,7 @@ void Session::feed_in_logic(shared_ptr logic) return; } - if (!cur_logic_snapshot_) + if (!cur_logic_segment_) { // This could be the first packet after a trigger set_capture_state(Running); @@ -522,11 +522,11 @@ void Session::feed_in_logic(shared_ptr logic) VariantBase::cast_dynamic>( device_->config_get(ConfigKey::LIMIT_SAMPLES)).get() : 0; - // Create a new data snapshot - cur_logic_snapshot_ = shared_ptr( - new data::LogicSnapshot( + // Create a new data segment + cur_logic_segment_ = shared_ptr( + new data::LogicSegment( logic, cur_samplerate_, sample_limit)); - logic_data_->push_snapshot(cur_logic_snapshot_); + logic_data_->push_segment(cur_logic_segment_); // @todo Putting this here means that only listeners querying // for logic will be notified. Currently the only user of @@ -536,8 +536,8 @@ void Session::feed_in_logic(shared_ptr logic) } else { - // Append to the existing data snapshot - cur_logic_snapshot_->append_payload(logic); + // Append to the existing data segment + cur_logic_segment_->append_payload(logic); } data_received(); @@ -555,18 +555,18 @@ void Session::feed_in_analog(shared_ptr analog) for (auto channel : channels) { - shared_ptr snapshot; + shared_ptr segment; - // Try to get the snapshot of the channel - const map< shared_ptr, shared_ptr >:: - iterator iter = cur_analog_snapshots_.find(channel); - if (iter != cur_analog_snapshots_.end()) - snapshot = (*iter).second; + // Try to get the segment of the channel + const map< shared_ptr, shared_ptr >:: + iterator iter = cur_analog_segments_.find(channel); + if (iter != cur_analog_segments_.end()) + segment = (*iter).second; else { - // If no snapshot was found, this means we havn't + // If no segment was found, this means we havn't // created one yet. i.e. this is the first packet - // in the sweep containing this snapshot. + // in the sweep containing this segment. sweep_beginning = true; // Get sample limit. @@ -578,11 +578,11 @@ void Session::feed_in_analog(shared_ptr analog) sample_limit = 0; } - // Create a snapshot, keep it in the maps of channels - snapshot = shared_ptr( - new data::AnalogSnapshot( + // Create a segment, keep it in the maps of channels + segment = shared_ptr( + new data::AnalogSegment( cur_samplerate_, sample_limit)); - cur_analog_snapshots_[channel] = snapshot; + cur_analog_segments_[channel] = segment; // Find the annalog data associated with the channel shared_ptr sig = @@ -593,14 +593,14 @@ void Session::feed_in_analog(shared_ptr analog) shared_ptr data(sig->analog_data()); assert(data); - // Push the snapshot into the analog data. - data->push_snapshot(snapshot); + // Push the segment into the analog data. + data->push_segment(segment); } - assert(snapshot); + assert(segment); - // Append the samples in the snapshot - snapshot->append_interleaved_samples(data++, sample_count, + // Append the samples in the segment + segment->append_interleaved_samples(data++, sample_count, channel_count); } @@ -642,8 +642,8 @@ void Session::data_feed_in(shared_ptr device, shared_ptr packet) { { lock_guard lock(data_mutex_); - cur_logic_snapshot_.reset(); - cur_analog_snapshots_.clear(); + cur_logic_segment_.reset(); + cur_analog_segments_.clear(); } frame_ended(); break; diff --git a/pv/session.hpp b/pv/session.hpp index 556f54e5..ba07fdcf 100644 --- a/pv/session.hpp +++ b/pv/session.hpp @@ -53,9 +53,9 @@ class DeviceManager; namespace data { class Analog; -class AnalogSnapshot; +class AnalogSegment; class Logic; -class LogicSnapshot; +class LogicSegment; class SignalData; } @@ -167,9 +167,9 @@ private: mutable std::mutex data_mutex_; std::shared_ptr logic_data_; uint64_t cur_samplerate_; - std::shared_ptr cur_logic_snapshot_; - std::map< std::shared_ptr, std::shared_ptr > - cur_analog_snapshots_; + std::shared_ptr cur_logic_segment_; + std::map< std::shared_ptr, std::shared_ptr > + cur_analog_segments_; std::thread sampling_thread_; diff --git a/pv/storesession.cpp b/pv/storesession.cpp index af599db0..6ecde13a 100644 --- a/pv/storesession.cpp +++ b/pv/storesession.cpp @@ -24,7 +24,7 @@ #include #include -#include +#include #include #include @@ -106,17 +106,17 @@ bool StoreSession::start() return false; } - // Get the snapshot - const deque< shared_ptr > &snapshots = - data->logic_snapshots(); + // Get the segment + const deque< shared_ptr > &segments = + data->logic_segments(); - if (snapshots.empty()) { - error_ = tr("No snapshots to save."); + if (segments.empty()) { + error_ = tr("No segments to save."); return false; } - const shared_ptr snapshot(snapshots.front()); - assert(snapshot); + const shared_ptr segment(segments.front()); + assert(segment); // Begin storing try { @@ -128,14 +128,14 @@ bool StoreSession::start() Glib::Variant::create(file_name_)}}); auto meta = context->create_meta_packet( {{ConfigKey::SAMPLERATE, Glib::Variant::create( - snapshot->samplerate())}}); + segment->samplerate())}}); output_->receive(meta); } catch (Error error) { error_ = tr("Error while saving."); return false; } - thread_ = std::thread(&StoreSession::store_proc, this, snapshot); + thread_ = std::thread(&StoreSession::store_proc, this, segment); return true; } @@ -150,9 +150,9 @@ void StoreSession::cancel() interrupt_ = true; } -void StoreSession::store_proc(shared_ptr snapshot) +void StoreSession::store_proc(shared_ptr segment) { - assert(snapshot); + assert(segment); uint64_t start_sample = 0, sample_count; unsigned progress_scale = 0; @@ -161,10 +161,10 @@ void StoreSession::store_proc(shared_ptr snapshot) uint8_t *const data = new uint8_t[BlockSize]; assert(data); - const int unit_size = snapshot->unit_size(); + const int unit_size = segment->unit_size(); assert(unit_size != 0); - sample_count = snapshot->get_sample_count(); + sample_count = segment->get_sample_count(); // Qt needs the progress values to fit inside an int. If they would // not, scale the current and max values down until they do. @@ -181,7 +181,7 @@ void StoreSession::store_proc(shared_ptr snapshot) const uint64_t end_sample = min( start_sample + samples_per_block, sample_count); - snapshot->get_samples(data, start_sample, end_sample); + segment->get_samples(data, start_sample, end_sample); size_t length = end_sample - start_sample; diff --git a/pv/storesession.hpp b/pv/storesession.hpp index 62cf1895..9094ca12 100644 --- a/pv/storesession.hpp +++ b/pv/storesession.hpp @@ -39,7 +39,7 @@ namespace pv { class Session; namespace data { -class LogicSnapshot; +class LogicSegment; } class StoreSession : public QObject @@ -66,7 +66,7 @@ public: void cancel(); private: - void store_proc(std::shared_ptr snapshot); + void store_proc(std::shared_ptr segment); Q_SIGNALS: void progress_updated(); diff --git a/pv/view/analogsignal.cpp b/pv/view/analogsignal.cpp index e559a4a4..5b6d8a50 100644 --- a/pv/view/analogsignal.cpp +++ b/pv/view/analogsignal.cpp @@ -25,7 +25,7 @@ #include "analogsignal.hpp" #include "pv/data/analog.hpp" -#include "pv/data/analogsnapshot.hpp" +#include "pv/data/analogsegment.hpp" #include "pv/view/view.hpp" #include @@ -103,18 +103,18 @@ void AnalogSignal::paint_mid(QPainter &p, const RowItemPaintParams &pp) if (!channel_->enabled()) return; - const deque< shared_ptr > &snapshots = - data_->analog_snapshots(); - if (snapshots.empty()) + const deque< shared_ptr > &segments = + data_->analog_segments(); + if (segments.empty()) return; - const shared_ptr &snapshot = - snapshots.front(); + const shared_ptr &segment = + segments.front(); const double pixels_offset = pp.pixels_offset(); - const double samplerate = snapshot->samplerate(); - const double start_time = snapshot->start_time(); - const int64_t last_sample = snapshot->get_sample_count() - 1; + const double samplerate = segment->samplerate(); + const double start_time = segment->start_time(); + const int64_t last_sample = segment->get_sample_count() - 1; const double samples_per_pixel = samplerate * pp.scale(); const double start = samplerate * (pp.offset() - start_time); const double end = start + samples_per_pixel * pp.width(); @@ -125,23 +125,23 @@ void AnalogSignal::paint_mid(QPainter &p, const RowItemPaintParams &pp) (int64_t)0), last_sample); if (samples_per_pixel < EnvelopeThreshold) - paint_trace(p, snapshot, y, pp.left(), + paint_trace(p, segment, y, pp.left(), start_sample, end_sample, pixels_offset, samples_per_pixel); else - paint_envelope(p, snapshot, y, pp.left(), + paint_envelope(p, segment, y, pp.left(), start_sample, end_sample, pixels_offset, samples_per_pixel); } void AnalogSignal::paint_trace(QPainter &p, - const shared_ptr &snapshot, + const shared_ptr &segment, int y, int left, const int64_t start, const int64_t end, const double pixels_offset, const double samples_per_pixel) { const int64_t sample_count = end - start; - const float *const samples = snapshot->get_samples(start, end); + const float *const samples = segment->get_samples(start, end); assert(samples); p.setPen(colour_); @@ -163,14 +163,14 @@ void AnalogSignal::paint_trace(QPainter &p, } void AnalogSignal::paint_envelope(QPainter &p, - const shared_ptr &snapshot, + const shared_ptr &segment, int y, int left, const int64_t start, const int64_t end, const double pixels_offset, const double samples_per_pixel) { - using pv::data::AnalogSnapshot; + using pv::data::AnalogSegment; - AnalogSnapshot::EnvelopeSection e; - snapshot->get_envelope_section(e, start, end, samples_per_pixel); + AnalogSegment::EnvelopeSection e; + segment->get_envelope_section(e, start, end, samples_per_pixel); if (e.length < 2) return; @@ -184,7 +184,7 @@ void AnalogSignal::paint_envelope(QPainter &p, for(uint64_t sample = 0; sample < e.length-1; sample++) { const float x = ((e.scale * sample + e.start) / samples_per_pixel - pixels_offset) + left; - const AnalogSnapshot::EnvelopeSample *const s = + const AnalogSegment::EnvelopeSample *const s = e.samples + sample; // We overlap this sample with the next so that vertical diff --git a/pv/view/analogsignal.hpp b/pv/view/analogsignal.hpp index c048371e..ad2b25ae 100644 --- a/pv/view/analogsignal.hpp +++ b/pv/view/analogsignal.hpp @@ -29,7 +29,7 @@ namespace pv { namespace data { class Analog; -class AnalogSnapshot; +class AnalogSegment; } namespace view { @@ -77,12 +77,12 @@ public: private: void paint_trace(QPainter &p, - const std::shared_ptr &snapshot, + const std::shared_ptr &segment, int y, int left, const int64_t start, const int64_t end, const double pixels_offset, const double samples_per_pixel); void paint_envelope(QPainter &p, - const std::shared_ptr &snapshot, + const std::shared_ptr &segment, int y, int left, const int64_t start, const int64_t end, const double pixels_offset, const double samples_per_pixel); diff --git a/pv/view/decodetrace.cpp b/pv/view/decodetrace.cpp index bdae3952..5392b17e 100644 --- a/pv/view/decodetrace.cpp +++ b/pv/view/decodetrace.cpp @@ -45,7 +45,7 @@ extern "C" { #include #include #include -#include +#include #include #include #include @@ -474,20 +474,20 @@ void DecodeTrace::draw_unresolved_period(QPainter &p, int h, int left, // We get the logic data of the first channel in the list. // This works because we are currently assuming all - // LogicSignals have the same data/snapshot + // LogicSignals have the same data/segment for (const shared_ptr &dec : stack) if (dec && !dec->channels().empty() && ((logic_signal = (*dec->channels().begin()).second)) && ((data = logic_signal->logic_data()))) break; - if (!data || data->logic_snapshots().empty()) + if (!data || data->logic_segments().empty()) return; - const shared_ptr snapshot = - data->logic_snapshots().front(); - assert(snapshot); - const int64_t sample_count = (int64_t)snapshot->get_sample_count(); + const shared_ptr segment = + data->logic_segments().front(); + assert(segment); + const int64_t sample_count = (int64_t)segment->get_sample_count(); if (sample_count == 0) return; diff --git a/pv/view/logicsignal.cpp b/pv/view/logicsignal.cpp index b1aaae8f..48d2debc 100644 --- a/pv/view/logicsignal.cpp +++ b/pv/view/logicsignal.cpp @@ -34,7 +34,7 @@ #include #include #include -#include +#include #include #include @@ -169,28 +169,28 @@ void LogicSignal::paint_mid(QPainter &p, const RowItemPaintParams &pp) const float high_offset = y - SignalHeight + 0.5f; const float low_offset = y + 0.5f; - const deque< shared_ptr > &snapshots = - data_->logic_snapshots(); - if (snapshots.empty()) + const deque< shared_ptr > &segments = + data_->logic_segments(); + if (segments.empty()) return; - const shared_ptr &snapshot = - snapshots.front(); + const shared_ptr &segment = + segments.front(); - double samplerate = snapshot->samplerate(); + double samplerate = segment->samplerate(); // Show sample rate as 1Hz when it is unknown if (samplerate == 0.0) samplerate = 1.0; const double pixels_offset = pp.pixels_offset(); - const double start_time = snapshot->start_time(); - const int64_t last_sample = snapshot->get_sample_count() - 1; + const double start_time = segment->start_time(); + const int64_t last_sample = segment->get_sample_count() - 1; const double samples_per_pixel = samplerate * pp.scale(); const double start = samplerate * (pp.offset() - start_time); const double end = start + samples_per_pixel * pp.width(); - snapshot->get_subsampled_edges(edges, + segment->get_subsampled_edges(edges, min(max((int64_t)floor(start), (int64_t)0), last_sample), min(max((int64_t)ceil(end), (int64_t)0), last_sample), samples_per_pixel / Oversampling, channel_->index()); diff --git a/pv/view/view.cpp b/pv/view/view.cpp index e0c49c20..03848478 100644 --- a/pv/view/view.cpp +++ b/pv/view/view.cpp @@ -50,14 +50,14 @@ #include "pv/session.hpp" #include "pv/data/logic.hpp" -#include "pv/data/logicsnapshot.hpp" +#include "pv/data/logicsegment.hpp" #include "pv/util.hpp" using boost::shared_lock; using boost::shared_mutex; using pv::data::SignalData; -using pv::data::Snapshot; +using pv::data::Segment; using pv::util::format_time; using std::back_inserter; @@ -263,9 +263,9 @@ void View::zoom_one_to_one() double samplerate = 0.0; for (const shared_ptr d : visible_data) { assert(d); - const vector< shared_ptr > snapshots = - d->snapshots(); - for (const shared_ptr &s : snapshots) + const vector< shared_ptr > segments = + d->segments(); + for (const shared_ptr &s : segments) samplerate = max(samplerate, s->samplerate()); } @@ -314,9 +314,9 @@ pair View::get_time_extents() const const set< shared_ptr > visible_data = get_visible_data(); for (const shared_ptr d : visible_data) { - const vector< shared_ptr > snapshots = - d->snapshots(); - for (const shared_ptr &s : snapshots) { + const vector< shared_ptr > segments = + d->segments(); + for (const shared_ptr &s : segments) { double samplerate = s->samplerate(); samplerate = (samplerate <= 0.0) ? 1.0 : samplerate; diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 891d22cb..b0b0b551 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -24,11 +24,11 @@ set(pulseview_TEST_SOURCES ${PROJECT_SOURCE_DIR}/pv/storesession.cpp ${PROJECT_SOURCE_DIR}/pv/util.cpp ${PROJECT_SOURCE_DIR}/pv/data/analog.cpp - ${PROJECT_SOURCE_DIR}/pv/data/analogsnapshot.cpp + ${PROJECT_SOURCE_DIR}/pv/data/analogsegment.cpp ${PROJECT_SOURCE_DIR}/pv/data/logic.cpp - ${PROJECT_SOURCE_DIR}/pv/data/logicsnapshot.cpp + ${PROJECT_SOURCE_DIR}/pv/data/logicsegment.cpp + ${PROJECT_SOURCE_DIR}/pv/data/segment.cpp ${PROJECT_SOURCE_DIR}/pv/data/signaldata.cpp - ${PROJECT_SOURCE_DIR}/pv/data/snapshot.cpp ${PROJECT_SOURCE_DIR}/pv/prop/bool.cpp ${PROJECT_SOURCE_DIR}/pv/prop/double.cpp ${PROJECT_SOURCE_DIR}/pv/prop/enum.cpp @@ -63,8 +63,8 @@ set(pulseview_TEST_SOURCES ${PROJECT_SOURCE_DIR}/pv/widgets/popuptoolbutton.cpp ${PROJECT_SOURCE_DIR}/pv/widgets/sweeptimingwidget.cpp ${PROJECT_SOURCE_DIR}/pv/widgets/wellarray.cpp - data/analogsnapshot.cpp - data/logicsnapshot.cpp + data/analogsegment.cpp + data/logicsegment.cpp test.cpp ) diff --git a/test/data/analogsnapshot.cpp b/test/data/analogsegment.cpp similarity index 72% rename from test/data/analogsnapshot.cpp rename to test/data/analogsegment.cpp index ff2b7208..fd7b8870 100644 --- a/test/data/analogsnapshot.cpp +++ b/test/data/analogsegment.cpp @@ -24,14 +24,14 @@ #include -#include +#include -using pv::data::AnalogSnapshot; +using pv::data::AnalogSegment; #if 0 -BOOST_AUTO_TEST_SUITE(AnalogSnapshotTest) +BOOST_AUTO_TEST_SUITE(AnalogSegmentTest) -void push_analog(AnalogSnapshot &s, unsigned int num_samples, +void push_analog(AnalogSegment &s, unsigned int num_samples, float value) { float *const data = new float[num_samples]; @@ -44,15 +44,15 @@ void push_analog(AnalogSnapshot &s, unsigned int num_samples, BOOST_AUTO_TEST_CASE(Basic) { - // Create an empty AnalogSnapshot object - AnalogSnapshot s; + // Create an empty AnalogSegment object + AnalogSegment s; - //----- Test AnalogSnapshot::push_analog -----// + //----- Test AnalogSegment::push_analog -----// BOOST_CHECK(s.get_sample_count() == 0); - for (unsigned int i = 0; i < AnalogSnapshot::ScaleStepCount; i++) + for (unsigned int i = 0; i < AnalogSegment::ScaleStepCount; i++) { - const AnalogSnapshot::Envelope &m = s.envelope_levels_[i]; + const AnalogSegment::Envelope &m = s.envelope_levels_[i]; BOOST_CHECK_EQUAL(m.length, 0); BOOST_CHECK_EQUAL(m.data_length, 0); BOOST_CHECK(m.samples == NULL); @@ -64,9 +64,9 @@ BOOST_AUTO_TEST_CASE(Basic) BOOST_CHECK(s.get_sample_count() == 8); // There should not be enough samples to have a single mip map sample - for (unsigned int i = 0; i < AnalogSnapshot::ScaleStepCount; i++) + for (unsigned int i = 0; i < AnalogSegment::ScaleStepCount; i++) { - const AnalogSnapshot::Envelope &m = s.envelope_levels_[i]; + const AnalogSegment::Envelope &m = s.envelope_levels_[i]; BOOST_CHECK_EQUAL(m.length, 0); BOOST_CHECK_EQUAL(m.data_length, 0); BOOST_CHECK(m.samples == NULL); @@ -77,17 +77,17 @@ BOOST_AUTO_TEST_CASE(Basic) // There should now be enough data for exactly one sample // in mip map level 0, and that sample should be 0 - const AnalogSnapshot::Envelope &e0 = s.envelope_levels_[0]; + const AnalogSegment::Envelope &e0 = s.envelope_levels_[0]; BOOST_CHECK_EQUAL(e0.length, 1); - BOOST_CHECK_EQUAL(e0.data_length, AnalogSnapshot::EnvelopeDataUnit); + BOOST_CHECK_EQUAL(e0.data_length, AnalogSegment::EnvelopeDataUnit); BOOST_REQUIRE(e0.samples != NULL); BOOST_CHECK_EQUAL(e0.samples[0].min, 0.0f); BOOST_CHECK_EQUAL(e0.samples[0].max, 1.0f); // The higher levels should still be empty - for (unsigned int i = 1; i < AnalogSnapshot::ScaleStepCount; i++) + for (unsigned int i = 1; i < AnalogSegment::ScaleStepCount; i++) { - const AnalogSnapshot::Envelope &m = s.envelope_levels_[i]; + const AnalogSegment::Envelope &m = s.envelope_levels_[i]; BOOST_CHECK_EQUAL(m.length, 0); BOOST_CHECK_EQUAL(m.data_length, 0); BOOST_CHECK(m.samples == NULL); @@ -97,16 +97,16 @@ BOOST_AUTO_TEST_CASE(Basic) push_analog(s, 240, -1.0f); BOOST_CHECK_EQUAL(e0.length, 16); - BOOST_CHECK_EQUAL(e0.data_length, AnalogSnapshot::EnvelopeDataUnit); + BOOST_CHECK_EQUAL(e0.data_length, AnalogSegment::EnvelopeDataUnit); for (unsigned int i = 1; i < e0.length; i++) { BOOST_CHECK_EQUAL(e0.samples[i].min, -1.0f); BOOST_CHECK_EQUAL(e0.samples[i].max, -1.0f); } - const AnalogSnapshot::Envelope &e1 = s.envelope_levels_[1]; + const AnalogSegment::Envelope &e1 = s.envelope_levels_[1]; BOOST_CHECK_EQUAL(e1.length, 1); - BOOST_CHECK_EQUAL(e1.data_length, AnalogSnapshot::EnvelopeDataUnit); + BOOST_CHECK_EQUAL(e1.data_length, AnalogSegment::EnvelopeDataUnit); BOOST_REQUIRE(e1.samples != NULL); BOOST_CHECK_EQUAL(e1.samples[0].min, -1.0f); BOOST_CHECK_EQUAL(e1.samples[0].max, 1.0f); diff --git a/test/data/logicsnapshot.cpp b/test/data/logicsegment.cpp similarity index 81% rename from test/data/logicsnapshot.cpp rename to test/data/logicsegment.cpp index 9f973932..29bffdda 100644 --- a/test/data/logicsnapshot.cpp +++ b/test/data/logicsegment.cpp @@ -24,9 +24,9 @@ #include -#include +#include -using pv::data::LogicSnapshot; +using pv::data::LogicSegment; using std::vector; // Dummy, remove again when unit tests are fixed. @@ -38,9 +38,9 @@ BOOST_AUTO_TEST_CASE(DummyTestCase) BOOST_AUTO_TEST_SUITE_END() #if 0 -BOOST_AUTO_TEST_SUITE(LogicSnapshotTest) +BOOST_AUTO_TEST_SUITE(LogicSegmentTest) -void push_logic(LogicSnapshot &s, unsigned int length, uint8_t value) +void push_logic(LogicSegment &s, unsigned int length, uint8_t value) { sr_datafeed_logic logic; logic.unitsize = 1; @@ -53,37 +53,37 @@ void push_logic(LogicSnapshot &s, unsigned int length, uint8_t value) BOOST_AUTO_TEST_CASE(Pow2) { - BOOST_CHECK_EQUAL(LogicSnapshot::pow2_ceil(0, 0), 0); - BOOST_CHECK_EQUAL(LogicSnapshot::pow2_ceil(1, 0), 1); - BOOST_CHECK_EQUAL(LogicSnapshot::pow2_ceil(2, 0), 2); + BOOST_CHECK_EQUAL(LogicSegment::pow2_ceil(0, 0), 0); + BOOST_CHECK_EQUAL(LogicSegment::pow2_ceil(1, 0), 1); + BOOST_CHECK_EQUAL(LogicSegment::pow2_ceil(2, 0), 2); BOOST_CHECK_EQUAL( - LogicSnapshot::pow2_ceil(INT64_MIN, 0), INT64_MIN); + LogicSegment::pow2_ceil(INT64_MIN, 0), INT64_MIN); BOOST_CHECK_EQUAL( - LogicSnapshot::pow2_ceil(INT64_MAX, 0), INT64_MAX); + LogicSegment::pow2_ceil(INT64_MAX, 0), INT64_MAX); - BOOST_CHECK_EQUAL(LogicSnapshot::pow2_ceil(0, 1), 0); - BOOST_CHECK_EQUAL(LogicSnapshot::pow2_ceil(1, 1), 2); - BOOST_CHECK_EQUAL(LogicSnapshot::pow2_ceil(2, 1), 2); - BOOST_CHECK_EQUAL(LogicSnapshot::pow2_ceil(3, 1), 4); + BOOST_CHECK_EQUAL(LogicSegment::pow2_ceil(0, 1), 0); + BOOST_CHECK_EQUAL(LogicSegment::pow2_ceil(1, 1), 2); + BOOST_CHECK_EQUAL(LogicSegment::pow2_ceil(2, 1), 2); + BOOST_CHECK_EQUAL(LogicSegment::pow2_ceil(3, 1), 4); } BOOST_AUTO_TEST_CASE(Basic) { - // Create an empty LogicSnapshot object + // Create an empty LogicSegment object sr_datafeed_logic logic; logic.length = 0; logic.unitsize = 1; logic.data = NULL; - LogicSnapshot s(logic); + LogicSegment s(logic); - //----- Test LogicSnapshot::push_logic -----// + //----- Test LogicSegment::push_logic -----// BOOST_CHECK(s.get_sample_count() == 0); - for (unsigned int i = 0; i < LogicSnapshot::ScaleStepCount; i++) + for (unsigned int i = 0; i < LogicSegment::ScaleStepCount; i++) { - const LogicSnapshot::MipMapLevel &m = s.mip_map_[i]; + const LogicSegment::MipMapLevel &m = s.mip_map_[i]; BOOST_CHECK_EQUAL(m.length, 0); BOOST_CHECK_EQUAL(m.data_length, 0); BOOST_CHECK(m.data == NULL); @@ -95,9 +95,9 @@ BOOST_AUTO_TEST_CASE(Basic) BOOST_CHECK(s.get_sample_count() == 8); // There should not be enough samples to have a single mip map sample - for (unsigned int i = 0; i < LogicSnapshot::ScaleStepCount; i++) + for (unsigned int i = 0; i < LogicSegment::ScaleStepCount; i++) { - const LogicSnapshot::MipMapLevel &m = s.mip_map_[i]; + const LogicSegment::MipMapLevel &m = s.mip_map_[i]; BOOST_CHECK_EQUAL(m.length, 0); BOOST_CHECK_EQUAL(m.data_length, 0); BOOST_CHECK(m.data == NULL); @@ -108,16 +108,16 @@ BOOST_AUTO_TEST_CASE(Basic) // There should now be enough data for exactly one sample // in mip map level 0, and that sample should be 0 - const LogicSnapshot::MipMapLevel &m0 = s.mip_map_[0]; + const LogicSegment::MipMapLevel &m0 = s.mip_map_[0]; BOOST_CHECK_EQUAL(m0.length, 1); - BOOST_CHECK_EQUAL(m0.data_length, LogicSnapshot::MipMapDataUnit); + BOOST_CHECK_EQUAL(m0.data_length, LogicSegment::MipMapDataUnit); BOOST_REQUIRE(m0.data != NULL); BOOST_CHECK_EQUAL(((uint8_t*)m0.data)[0], 0x11); // The higher levels should still be empty - for (unsigned int i = 1; i < LogicSnapshot::ScaleStepCount; i++) + for (unsigned int i = 1; i < LogicSegment::ScaleStepCount; i++) { - const LogicSnapshot::MipMapLevel &m = s.mip_map_[i]; + const LogicSegment::MipMapLevel &m = s.mip_map_[i]; BOOST_CHECK_EQUAL(m.length, 0); BOOST_CHECK_EQUAL(m.data_length, 0); BOOST_CHECK(m.data == NULL); @@ -127,22 +127,22 @@ BOOST_AUTO_TEST_CASE(Basic) push_logic(s, 240, 0); BOOST_CHECK_EQUAL(m0.length, 16); - BOOST_CHECK_EQUAL(m0.data_length, LogicSnapshot::MipMapDataUnit); + BOOST_CHECK_EQUAL(m0.data_length, LogicSegment::MipMapDataUnit); BOOST_CHECK_EQUAL(((uint8_t*)m0.data)[1], 0x11); for (unsigned int i = 2; i < m0.length; i++) BOOST_CHECK_EQUAL(((uint8_t*)m0.data)[i], 0); - const LogicSnapshot::MipMapLevel &m1 = s.mip_map_[1]; + const LogicSegment::MipMapLevel &m1 = s.mip_map_[1]; BOOST_CHECK_EQUAL(m1.length, 1); - BOOST_CHECK_EQUAL(m1.data_length, LogicSnapshot::MipMapDataUnit); + BOOST_CHECK_EQUAL(m1.data_length, LogicSegment::MipMapDataUnit); BOOST_REQUIRE(m1.data != NULL); BOOST_CHECK_EQUAL(((uint8_t*)m1.data)[0], 0x11); - //----- Test LogicSnapshot::get_subsampled_edges -----// + //----- Test LogicSegment::get_subsampled_edges -----// // Test a full view at full zoom. - vector edges; + vector edges; s.get_subsampled_edges(edges, 0, 255, 1, 0); BOOST_REQUIRE_EQUAL(edges.size(), 4); @@ -176,7 +176,7 @@ BOOST_AUTO_TEST_CASE(LargeData) for (unsigned int i = 0; i < Length; i++) *data++ = (uint8_t)(i >> 8); - LogicSnapshot s(logic); + LogicSegment s(logic); delete[] (uint8_t*)logic.data; BOOST_CHECK(s.get_sample_count() == Length); @@ -184,7 +184,7 @@ BOOST_AUTO_TEST_CASE(LargeData) // Check mip map level 0 BOOST_CHECK_EQUAL(s.mip_map_[0].length, 62500); BOOST_CHECK_EQUAL(s.mip_map_[0].data_length, - LogicSnapshot::MipMapDataUnit); + LogicSegment::MipMapDataUnit); BOOST_REQUIRE(s.mip_map_[0].data != NULL); prev_sample = 0; @@ -207,7 +207,7 @@ BOOST_AUTO_TEST_CASE(LargeData) // Check mip map level 1 BOOST_CHECK_EQUAL(s.mip_map_[1].length, 3906); BOOST_CHECK_EQUAL(s.mip_map_[1].data_length, - LogicSnapshot::MipMapDataUnit); + LogicSegment::MipMapDataUnit); BOOST_REQUIRE(s.mip_map_[1].data != NULL); prev_sample = 0; @@ -225,7 +225,7 @@ BOOST_AUTO_TEST_CASE(LargeData) // Check mip map level 2 BOOST_CHECK_EQUAL(s.mip_map_[2].length, 244); BOOST_CHECK_EQUAL(s.mip_map_[2].data_length, - LogicSnapshot::MipMapDataUnit); + LogicSegment::MipMapDataUnit); BOOST_REQUIRE(s.mip_map_[2].data != NULL); prev_sample = 0; @@ -243,7 +243,7 @@ BOOST_AUTO_TEST_CASE(LargeData) // Check mip map level 3 BOOST_CHECK_EQUAL(s.mip_map_[3].length, 15); BOOST_CHECK_EQUAL(s.mip_map_[3].data_length, - LogicSnapshot::MipMapDataUnit); + LogicSegment::MipMapDataUnit); BOOST_REQUIRE(s.mip_map_[3].data != NULL); for (unsigned int i = 0; i < s.mip_map_[3].length; i++) @@ -251,17 +251,17 @@ BOOST_AUTO_TEST_CASE(LargeData) 0xFF); // Check the higher levels - for (unsigned int i = 4; i < LogicSnapshot::ScaleStepCount; i++) + for (unsigned int i = 4; i < LogicSegment::ScaleStepCount; i++) { - const LogicSnapshot::MipMapLevel &m = s.mip_map_[i]; + const LogicSegment::MipMapLevel &m = s.mip_map_[i]; BOOST_CHECK_EQUAL(m.length, 0); BOOST_CHECK_EQUAL(m.data_length, 0); BOOST_CHECK(m.data == NULL); } - //----- Test LogicSnapshot::get_subsampled_edges -----// + //----- Test LogicSegment::get_subsampled_edges -----// // Check in normal case - vector edges; + vector edges; s.get_subsampled_edges(edges, 0, Length-1, 1, 7); BOOST_CHECK_EQUAL(edges.size(), 32); @@ -287,9 +287,9 @@ BOOST_AUTO_TEST_CASE(Pulses) const int Period = 64; const int Length = Cycles * Period; - vector edges; + vector edges; - //----- Create a LogicSnapshot -----// + //----- Create a LogicSegment -----// sr_datafeed_logic logic; logic.unitsize = 1; logic.length = Length; @@ -302,14 +302,14 @@ BOOST_AUTO_TEST_CASE(Pulses) *p++ = 0x00; } - LogicSnapshot s(logic); + LogicSegment s(logic); delete[] (uint8_t*)logic.data; //----- Check the mip-map -----// // Check mip map level 0 BOOST_CHECK_EQUAL(s.mip_map_[0].length, 12); BOOST_CHECK_EQUAL(s.mip_map_[0].data_length, - LogicSnapshot::MipMapDataUnit); + LogicSegment::MipMapDataUnit); BOOST_REQUIRE(s.mip_map_[0].data != NULL); for (unsigned int i = 0; i < s.mip_map_[0].length;) { @@ -318,7 +318,7 @@ BOOST_AUTO_TEST_CASE(Pulses) for (int j = 1; i < s.mip_map_[0].length && - j < Period/LogicSnapshot::MipMapScaleFactor; j++) { + j < Period/LogicSegment::MipMapScaleFactor; j++) { BOOST_TEST_MESSAGE( "Testing mip_map[0].data[" << i << "]"); BOOST_CHECK_EQUAL(s.get_subsample(0, i++) & 0xFF, 0x00); @@ -326,8 +326,8 @@ BOOST_AUTO_TEST_CASE(Pulses) } // Check the higher levels are all inactive - for (unsigned int i = 1; i < LogicSnapshot::ScaleStepCount; i++) { - const LogicSnapshot::MipMapLevel &m = s.mip_map_[i]; + for (unsigned int i = 1; i < LogicSegment::ScaleStepCount; i++) { + const LogicSegment::MipMapLevel &m = s.mip_map_[i]; BOOST_CHECK_EQUAL(m.length, 0); BOOST_CHECK_EQUAL(m.data_length, 0); BOOST_CHECK(m.data == NULL); @@ -350,9 +350,9 @@ BOOST_AUTO_TEST_CASE(LongPulses) const int Length = Cycles * Period; int j; - vector edges; + vector edges; - //----- Create a LogicSnapshot -----// + //----- Create a LogicSegment -----// sr_datafeed_logic logic; logic.unitsize = 8; logic.length = Length * 8; @@ -366,14 +366,14 @@ BOOST_AUTO_TEST_CASE(LongPulses) *p++ = 0; } - LogicSnapshot s(logic); + LogicSegment s(logic); delete[] (uint64_t*)logic.data; //----- Check the mip-map -----// // Check mip map level 0 BOOST_CHECK_EQUAL(s.mip_map_[0].length, 12); BOOST_CHECK_EQUAL(s.mip_map_[0].data_length, - LogicSnapshot::MipMapDataUnit); + LogicSegment::MipMapDataUnit); BOOST_REQUIRE(s.mip_map_[0].data != NULL); for (unsigned int i = 0; i < s.mip_map_[0].length;) { @@ -384,7 +384,7 @@ BOOST_AUTO_TEST_CASE(LongPulses) } for (; i < s.mip_map_[0].length && - j < Period/LogicSnapshot::MipMapScaleFactor; j++) { + j < Period/LogicSegment::MipMapScaleFactor; j++) { BOOST_TEST_MESSAGE( "Testing mip_map[0].data[" << i << "]"); BOOST_CHECK_EQUAL(s.get_subsample(0, i++), 0); @@ -392,8 +392,8 @@ BOOST_AUTO_TEST_CASE(LongPulses) } // Check the higher levels are all inactive - for (unsigned int i = 1; i < LogicSnapshot::ScaleStepCount; i++) { - const LogicSnapshot::MipMapLevel &m = s.mip_map_[i]; + for (unsigned int i = 1; i < LogicSegment::ScaleStepCount; i++) { + const LogicSegment::MipMapLevel &m = s.mip_map_[i]; BOOST_CHECK_EQUAL(m.length, 0); BOOST_CHECK_EQUAL(m.data_length, 0); BOOST_CHECK(m.data == NULL); @@ -447,7 +447,7 @@ BOOST_AUTO_TEST_CASE(LisaMUsbHid) bool state = false; int lastEdgePos = 0; - //----- Create a LogicSnapshot -----// + //----- Create a LogicSegment -----// sr_datafeed_logic logic; logic.unitsize = 1; logic.length = Length; @@ -463,10 +463,10 @@ BOOST_AUTO_TEST_CASE(LisaMUsbHid) state = !state; } - LogicSnapshot s(logic); + LogicSegment s(logic); delete[] (uint64_t*)logic.data; - vector edges; + vector edges; /* The trailing edge of the pulse train is falling in the source data. @@ -500,9 +500,9 @@ BOOST_AUTO_TEST_CASE(WideData) for (int i = 0; i < Length; i++) data[i] = 0x0FF0; - LogicSnapshot s(logic); + LogicSegment s(logic); - vector edges; + vector edges; edges.clear(); s.get_subsampled_edges(edges, 0, Length-1, 1, 0); @@ -532,9 +532,9 @@ BOOST_AUTO_TEST_CASE(Sixteen) for (int i = 0; i < Length; i++) data[i] = 0xFFFE; - LogicSnapshot s(logic); + LogicSegment s(logic); - vector edges; + vector edges; s.get_subsampled_edges(edges, 0, 2, 0.0004, 1); BOOST_CHECK_EQUAL(edges.size(), 2); -- 2.30.2