X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=pv%2Fdata%2Flogic.cpp;h=4a13e568bc80ff38770a245b1e9b38b1861d15a9;hb=76da6e9e2168f2f2c599d48ab587a48d2a110107;hp=7b42e47497054c3fc6d359bf3ac860bb577fc09f;hpb=1b1ec774978b65209ce2b454cbf81da499b797d2;p=pulseview.git diff --git a/pv/data/logic.cpp b/pv/data/logic.cpp index 7b42e474..4a13e568 100644 --- a/pv/data/logic.cpp +++ b/pv/data/logic.cpp @@ -14,40 +14,103 @@ * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * along with this program; if not, see . */ -#include "logic.h" -#include "logicsnapshot.h" +#include -using namespace boost; -using namespace std; +#include "logic.hpp" +#include "logicsegment.hpp" + +using std::deque; +using std::max; +using std::shared_ptr; +using std::vector; namespace pv { namespace data { -Logic::Logic(const sr_datafeed_meta_logic &meta, - uint64_t samplerate) : - SignalData(samplerate), - _num_probes(meta.num_probes) +Logic::Logic(unsigned int num_channels) : + SignalData(), + samplerate_(1), // Default is 1 Hz to prevent division-by-zero errors + num_channels_(num_channels) +{ + assert(num_channels_ > 0); +} + +unsigned int Logic::num_channels() const +{ + return num_channels_; +} + +void Logic::push_segment(shared_ptr &segment) +{ + segments_.push_back(segment); + + if ((samplerate_ == 1) && (segment->samplerate() > 1)) + samplerate_ = segment->samplerate(); + + connect(segment.get(), SIGNAL(completed()), this, SLOT(on_segment_completed())); +} + +const deque< shared_ptr >& Logic::logic_segments() const +{ + return segments_; +} + +deque< shared_ptr >& Logic::logic_segments() +{ + return segments_; +} + +vector< shared_ptr > Logic::segments() const +{ + return vector< shared_ptr >(segments_.begin(), segments_.end()); +} + +uint32_t Logic::get_segment_count() const +{ + return (uint32_t)segments_.size(); +} + +void Logic::clear() +{ + if (!segments_.empty()) { + segments_.clear(); + + samples_cleared(); + } +} + +void Logic::set_samplerate(double value) +{ + samplerate_ = value; +} + +double Logic::get_samplerate() const { + return samplerate_; } -int Logic::get_num_probes() const +uint64_t Logic::max_sample_count() const { - return _num_probes; + uint64_t l = 0; + for (const shared_ptr& s : segments_) { + assert(s); + l = max(l, s->get_sample_count()); + } + return l; } -void Logic::push_snapshot( - shared_ptr &snapshot) +void Logic::notify_samples_added(shared_ptr segment, uint64_t start_sample, + uint64_t end_sample) { - _snapshots.push_front(snapshot); + samples_added(segment, start_sample, end_sample); } -deque< shared_ptr >& Logic::get_snapshots() +void Logic::on_segment_completed() { - return _snapshots; + segment_completed(); } } // namespace data