X-Git-Url: http://git.code-monkey.de/?a=blobdiff_plain;f=pv%2Fdata%2Fdecodesignal.cpp;h=4061ef2760098ea32f810a98bd28e5535e35479f;hb=0c5fe73e5b66bf31d2dcfa2b2846a86cd2fdf0c4;hp=7a4a3d11269d0b22b397099cbf23a563133829cc;hpb=ff83d98059f06ac8f57be080ab53e7095aa4748b;p=pulseview.git diff --git a/pv/data/decodesignal.cpp b/pv/data/decodesignal.cpp index 7a4a3d1..4061ef2 100644 --- a/pv/data/decodesignal.cpp +++ b/pv/data/decodesignal.cpp @@ -17,6 +17,8 @@ * along with this program; if not, see . */ +#include + #include "logic.hpp" #include "logicsegment.hpp" #include "decodesignal.hpp" @@ -29,6 +31,7 @@ #include using std::make_shared; +using std::min; using std::shared_ptr; using pv::data::decode::Decoder; using pv::data::decode::Row; @@ -110,6 +113,11 @@ bool DecodeSignal::toggle_decoder_visibility(int index) return state; } +void DecodeSignal::begin_decode() +{ + decoder_stack_->begin_decode(); +} + QString DecodeSignal::error_message() const { return decoder_stack_->error_message(); @@ -155,29 +163,6 @@ void DecodeSignal::set_initial_pin_state(const uint16_t channel_id, const int in decoder_stack_->begin_decode(); } -int64_t DecodeSignal::sample_count() const -{ - shared_ptr data; - shared_ptr signalbase; - - // 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/segment - for (const shared_ptr &dec : decoder_stack_->stack()) - if (dec && !dec->channels().empty() && - ((signalbase = (*dec->channels().begin()).second)) && - ((data = signalbase->logic_data()))) - break; - - if (!data || data->logic_segments().empty()) - return 0; - - const shared_ptr segment = data->logic_segments().front(); - assert(segment); - - return (int64_t)segment->get_sample_count(); -} - double DecodeSignal::samplerate() const { return decoder_stack_->samplerate(); @@ -188,7 +173,34 @@ const pv::util::Timestamp& DecodeSignal::start_time() const return decoder_stack_->start_time(); } -int64_t DecodeSignal::samples_decoded() const +int64_t DecodeSignal::get_working_sample_count() const +{ + // The working sample count is the highest sample number for + // which all used signals have data available, so go through + // all channels and use the lowest overall sample count of the + // current segment + + // TODO Currently, we assume only a single segment exists + + int64_t count = std::numeric_limits::max(); + bool no_signals_assigned = true; + + for (const data::DecodeChannel &ch : channels_) + if (ch.assigned_signal) { + no_signals_assigned = false; + + const shared_ptr logic_data = ch.assigned_signal->logic_data(); + if (!logic_data || logic_data->logic_segments().empty()) + return 0; + + const shared_ptr segment = logic_data->logic_segments().front(); + count = min(count, (int64_t)segment->get_sample_count()); + } + + return (no_signals_assigned ? 0 : count); +} + +int64_t DecodeSignal::get_decoded_sample_count() const { return decoder_stack_->samples_decoded(); }