]> sigrok.org Git - pulseview.git/blob - pv/data/decodesignal.hpp
Move more functionality into DecodeSignal
[pulseview.git] / pv / data / decodesignal.hpp
1 /*
2  * This file is part of the PulseView project.
3  *
4  * Copyright (C) 2017 Soeren Apel <soeren@apelpie.net>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, see <http://www.gnu.org/licenses/>.
18  */
19
20 #ifndef PULSEVIEW_PV_DATA_DECODESIGNAL_HPP
21 #define PULSEVIEW_PV_DATA_DECODESIGNAL_HPP
22
23 #include <unordered_set>
24 #include <vector>
25
26 #include <QString>
27
28 #include <libsigrokdecode/libsigrokdecode.h>
29
30 #include <pv/data/signalbase.hpp>
31
32 using std::list;
33 using std::unordered_set;
34 using std::vector;
35 using std::shared_ptr;
36
37 namespace pv {
38 namespace data {
39
40 namespace decode {
41 class Annotation;
42 class Decoder;
43 class Row;
44 }
45
46 class DecoderStack;
47 class Logic;
48 class SignalBase;
49 class SignalData;
50
51 struct DecodeChannel
52 {
53         uint16_t id;  // Also tells which bit within a sample represents this channel
54         const bool is_optional;
55         const pv::data::SignalBase *assigned_signal;
56         const QString name, desc;
57         int initial_pin_state;
58         const shared_ptr<pv::data::decode::Decoder> decoder_;
59         const srd_channel *pdch_;
60 };
61
62 class DecodeSignal : public SignalBase
63 {
64         Q_OBJECT
65
66 public:
67         DecodeSignal(shared_ptr<pv::data::DecoderStack> decoder_stack,
68                 const unordered_set< shared_ptr<data::SignalBase> > &all_signals);
69         virtual ~DecodeSignal();
70
71         bool is_decode_signal() const;
72         shared_ptr<data::DecoderStack> decoder_stack() const;
73         const list< shared_ptr<data::decode::Decoder> >& decoder_stack_list() const;
74
75         void stack_decoder(srd_decoder *decoder);
76         void remove_decoder(int index);
77         bool toggle_decoder_visibility(int index);
78
79         QString error_message() const;
80
81         const list<data::DecodeChannel> get_channels() const;
82         void auto_assign_signals();
83         void assign_signal(const uint16_t channel_id, const SignalBase *signal);
84
85         void set_initial_pin_state(const uint16_t channel_id, const int init_state);
86
87         double samplerate() const;
88         const pv::util::Timestamp& start_time() const;
89         int64_t sample_count() const;
90         int64_t samples_decoded() const;
91
92         vector<decode::Row> visible_rows() const;
93
94         /**
95          * Extracts sorted annotations between two period into a vector.
96          */
97         void get_annotation_subset(
98                 vector<pv::data::decode::Annotation> &dest,
99                 const decode::Row &row, uint64_t start_sample,
100                 uint64_t end_sample) const;
101
102 private:
103         void update_channel_list();
104
105 Q_SIGNALS:
106         void new_annotations();
107         void channels_updated();
108
109 private Q_SLOTS:
110         void on_new_annotations();
111
112 private:
113         shared_ptr<pv::data::DecoderStack> decoder_stack_;
114         const unordered_set< shared_ptr<data::SignalBase> > &all_signals_;
115         list<data::DecodeChannel> channels_;
116 };
117
118 } // namespace data
119 } // namespace pv
120
121 #endif // PULSEVIEW_PV_DATA_DECODESIGNAL_HPP