]> sigrok.org Git - pulseview.git/blob - pv/data/decodesignal.hpp
Re-use DecodeTrace::ChannelSelector as DecodeChannel
[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 <vector>
24
25 #include <QString>
26
27 #include <libsigrokdecode/libsigrokdecode.h>
28
29 #include <pv/data/signalbase.hpp>
30
31 using std::list;
32 using std::vector;
33 using std::shared_ptr;
34
35 namespace pv {
36 namespace data {
37
38 namespace decode {
39 class Annotation;
40 class Decoder;
41 class Row;
42 }
43
44 class DecoderStack;
45 class Logic;
46 class SignalBase;
47 class SignalData;
48
49 struct DecodeChannel
50 {
51         uint16_t id;  // Also tells which bit within a sample represents this channel
52         const bool is_optional;
53         const pv::data::SignalBase *assigned_signal;
54         const QString name, desc;
55         int initial_pin_state;
56         const shared_ptr<pv::data::decode::Decoder> decoder_;
57         const srd_channel *pdch_;
58 };
59
60 class DecodeSignal : public SignalBase
61 {
62         Q_OBJECT
63
64 public:
65         DecodeSignal(shared_ptr<pv::data::DecoderStack> decoder_stack);
66         virtual ~DecodeSignal();
67
68         bool is_decode_signal() const;
69         shared_ptr<data::DecoderStack> decoder_stack() const;
70         const list< shared_ptr<data::decode::Decoder> >& decoder_stack_list() const;
71
72         void stack_decoder(srd_decoder *decoder);
73         void remove_decoder(int index);
74         bool toggle_decoder_visibility(int index);
75
76         QString error_message() const;
77
78         const list<data::DecodeChannel> get_channels() const;
79         void assign_signal(const uint16_t channel_id, const SignalBase *signal);
80
81         void set_initial_pin_state(const uint16_t channel_id, const int init_state);
82
83         vector<decode::Row> visible_rows() const;
84
85         /**
86          * Extracts sorted annotations between two period into a vector.
87          */
88         void get_annotation_subset(
89                 vector<pv::data::decode::Annotation> &dest,
90                 const decode::Row &row, uint64_t start_sample,
91                 uint64_t end_sample) const;
92
93 private:
94         void update_channel_list();
95
96 Q_SIGNALS:
97         void new_annotations();
98         void channels_updated();
99
100 private Q_SLOTS:
101         void on_new_annotations();
102
103 private:
104         shared_ptr<pv::data::DecoderStack> decoder_stack_;
105         list<data::DecodeChannel> channels_;
106 };
107
108 } // namespace data
109 } // namespace pv
110
111 #endif // PULSEVIEW_PV_DATA_DECODESIGNAL_HPP