2 * This file is part of the SmuView project.
4 * Copyright (C) 2012 Joel Holdsworth <joel@airwebreathe.org.uk>
5 * Copyright (C) 2016 Soeren Apel <soeren@apelpie.net>
6 * Copyright (C) 2016-2021 Frank Stettner <frank-stettner@gmx.net>
8 * This program is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #ifndef CHANNELS_BASECHANNEL_HPP
23 #define CHANNELS_BASECHANNEL_HPP
34 #include "src/data/datautil.hpp"
38 using std::shared_ptr
;
41 using sv::data::measured_quantity_t
;
50 class AnalogTimeSignal
;
60 enum class ChannelType
{
62 * Channels with analog data (Power supplies, loads, DMMs)
66 * Virtual channel for calculated data
70 * Virtual channel for user generated data (e.g. scripts)
77 public std::enable_shared_from_this
<BaseChannel
>
83 shared_ptr
<sigrok::Channel
> sr_channel
,
84 shared_ptr
<devices::BaseDevice
> parent_device
,
85 const set
<string
> &channel_group_names
,
86 double channel_start_timestamp
);
87 virtual ~BaseChannel();
91 * Return the underlying sigrok channel.
93 * HardwareChannels always have a sigrok channel, UserChannels only have a
94 * sigrok channel when created in a UserDevice!
96 shared_ptr
<sigrok::Channel
> sr_channel() const;
99 * Get the name of this channel, i.e. how the device calls it.
104 * Set the name of the signal.
106 void set_name(const string
&name
);
109 * Get the display name of this channel.
111 QString
display_name() const;
114 * Get the index number of this channel, i.e. a unique ID assigned by
117 unsigned int index() const;
120 * Get the type of this channel.
122 ChannelType
type() const;
125 * Return enabled status of this channel.
127 bool enabled() const;
130 * Set the enabled status of this channel.
132 void set_enabled(bool enabled
);
135 * Does this channel have just one signal, thats quantity doesn't change?
137 bool fixed_signal() const;
140 * Set if this channel has just one signal, thats quantity doesn't change
142 void set_fixed_signal(bool fixed_signal
);
145 * Return the device, this channel belongs to.
147 shared_ptr
<devices::BaseDevice
> parent_device();
150 * Get the channel group name, the channel is in. Returns "" if the channel
151 * is not in a channel group.
153 set
<string
> channel_group_names() const;
156 * Add a channel group name
158 void add_channel_group_name(const string
&channel_group_name
);
161 * Add a signal to the channel. For now only AnalogTimeSignals
164 void add_signal(shared_ptr
<data::AnalogTimeSignal
> signal
);
167 * Add a signal by its quantity, quantity_flags and unit.
169 shared_ptr
<data::BaseSignal
> add_signal(
170 data::Quantity quantity
,
171 set
<data::QuantityFlag
> quantity_flags
,
173 string custom_name
= "");
176 * Get the actual signal
178 shared_ptr
<data::BaseSignal
> actual_signal();
181 * Get all signals for this channel. Normaly a measurement quantity only
182 * has one corresponding signal, but for user channels this can be
185 map
<measured_quantity_t
, vector
<shared_ptr
<data::BaseSignal
>>> signal_map();
188 * Get all signals for this channel.
189 * This function is especially for the Python bindings.
191 vector
<shared_ptr
<data::BaseSignal
>> signals();
194 * Delete all signals from this channel
196 void clear_signals();
198 virtual void save_settings(QSettings
&settings
) const;
199 virtual void restore_settings(QSettings
&settings
);
202 static const size_t size_of_double_
= sizeof(double);
204 /** The corresponding sigrok channel object. */
205 shared_ptr
<sigrok::Channel
> sr_channel_
;
206 /** Name of this channel. */
208 /** Index of this channel. */
210 /** Type of this channel. */
212 /** Timestamp when this channel was created/started. */
213 double channel_start_timestamp_
;
215 /** The device this channel belongs to. */
216 shared_ptr
<devices::BaseDevice
> parent_device_
;
217 /** The channel group names this channel belongs to. */
218 set
<string
> channel_group_names_
;
221 shared_ptr
<data::BaseSignal
> actual_signal_
;
222 map
<measured_quantity_t
, vector
<shared_ptr
<data::BaseSignal
>>> signal_map_
;
225 void on_aquisition_start_timestamp_changed(double timestamp
);
228 void channel_start_timestamp_changed(double timestamp
);
229 void enabled_changed(const bool enabled
);
230 void name_changed(const std::string
&name
);
231 void signal_added(shared_ptr
<sv::data::BaseSignal
> signal
);
232 void signal_changed(shared_ptr
<sv::data::BaseSignal
> signal
);
236 } // namespace channels
239 #endif // CHANNELS_BASECHANNEL_HPP