]>
Commit | Line | Data |
---|---|---|
bf0edd2b SA |
1 | /* |
2 | * This file is part of the PulseView project. | |
3 | * | |
4 | * Copyright (C) 2012 Joel Holdsworth <joel@airwebreathe.org.uk> | |
5 | * Copyright (C) 2016 Soeren Apel <soeren@apelpie.net> | |
6 | * | |
7 | * This program is free software; you can redistribute it and/or modify | |
8 | * it under the terms of the GNU General Public License as published by | |
9 | * the Free Software Foundation; either version 2 of the License, or | |
10 | * (at your option) any later version. | |
11 | * | |
12 | * This program is distributed in the hope that it will be useful, | |
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | * GNU General Public License for more details. | |
16 | * | |
17 | * You should have received a copy of the GNU General Public License | |
efdec55a | 18 | * along with this program; if not, see <http://www.gnu.org/licenses/>. |
bf0edd2b SA |
19 | */ |
20 | ||
21 | #ifndef PULSEVIEW_PV_DATA_SIGNALBASE_HPP | |
22 | #define PULSEVIEW_PV_DATA_SIGNALBASE_HPP | |
23 | ||
27a3f09b SA |
24 | #include <atomic> |
25 | #include <condition_variable> | |
12ea3616 | 26 | #include <thread> |
52c900ac | 27 | #include <vector> |
12ea3616 | 28 | |
bf0edd2b SA |
29 | #include <QColor> |
30 | #include <QObject> | |
6de38b17 | 31 | #include <QSettings> |
bf0edd2b | 32 | #include <QString> |
932bc246 | 33 | #include <QTimer> |
52c900ac | 34 | #include <QVariant> |
bf0edd2b SA |
35 | |
36 | #include <libsigrokcxx/libsigrokcxx.hpp> | |
37 | ||
27a3f09b SA |
38 | using std::atomic; |
39 | using std::condition_variable; | |
52c900ac | 40 | using std::map; |
27a3f09b | 41 | using std::mutex; |
52c900ac | 42 | using std::pair; |
6f925ba9 | 43 | using std::shared_ptr; |
52c900ac | 44 | using std::vector; |
bf0edd2b SA |
45 | |
46 | namespace sigrok { | |
47 | class Channel; | |
bf0edd2b SA |
48 | } |
49 | ||
50 | namespace pv { | |
51 | namespace data { | |
52 | ||
cbd2a2de | 53 | class Analog; |
63253d72 | 54 | class AnalogSegment; |
bb7dd726 | 55 | class DecoderStack; |
cbd2a2de | 56 | class Logic; |
63253d72 | 57 | class LogicSegment; |
cbd2a2de SA |
58 | class SignalData; |
59 | ||
bf0edd2b SA |
60 | class SignalBase : public QObject |
61 | { | |
62 | Q_OBJECT | |
63 | ||
472a80c5 SA |
64 | public: |
65 | enum ChannelType { | |
64845ac2 SA |
66 | AnalogChannel = 1, ///< Analog data |
67 | LogicChannel, ///< Logic data | |
68 | DecodeChannel, ///< Protocol Decoder channel using libsigrokdecode | |
64845ac2 | 69 | MathChannel ///< Virtual channel generated by math operations |
472a80c5 SA |
70 | }; |
71 | ||
12ea3616 SA |
72 | enum ConversionType { |
73 | NoConversion = 0, | |
b9cdbe03 | 74 | A2LConversionByThreshold = 1, |
12ea3616 SA |
75 | A2LConversionBySchmittTrigger = 2 |
76 | }; | |
77 | ||
f0f9c856 SA |
78 | /** |
79 | * Conversion presets range from -1 to n, where 1..n are dependent on | |
80 | * the conversion these presets apply to. -1 and 0 have fixed meanings, | |
81 | * however. | |
82 | */ | |
83 | enum ConversionPreset { | |
84 | NoPreset = -1, ///< Conversion uses custom values | |
85 | DynamicPreset = 0 ///< Conversion uses calculated values | |
86 | }; | |
87 | ||
bf0edd2b | 88 | private: |
641574bc | 89 | static const int ColorBGAlpha; |
bcaf0334 | 90 | static const uint64_t ConversionBlockSize; |
932bc246 | 91 | static const uint32_t ConversionDelay; |
bf0edd2b SA |
92 | |
93 | public: | |
472a80c5 | 94 | SignalBase(shared_ptr<sigrok::Channel> channel, ChannelType channel_type); |
12ea3616 | 95 | virtual ~SignalBase(); |
bf0edd2b SA |
96 | |
97 | public: | |
98 | /** | |
99 | * Returns the underlying SR channel. | |
100 | */ | |
6f925ba9 | 101 | shared_ptr<sigrok::Channel> channel() const; |
bf0edd2b SA |
102 | |
103 | /** | |
104 | * Returns enabled status of this channel. | |
105 | */ | |
106 | bool enabled() const; | |
107 | ||
108 | /** | |
109 | * Sets the enabled status of this channel. | |
110 | * @param value Boolean value to set. | |
111 | */ | |
112 | void set_enabled(bool value); | |
113 | ||
114 | /** | |
115 | * Gets the type of this channel. | |
116 | */ | |
472a80c5 | 117 | ChannelType type() const; |
bf0edd2b SA |
118 | |
119 | /** | |
27a3f09b SA |
120 | * Gets the index number of this channel, i.e. a unique ID assigned by |
121 | * the device driver. | |
bf0edd2b SA |
122 | */ |
123 | unsigned int index() const; | |
124 | ||
27a3f09b SA |
125 | /** |
126 | * Returns which bit of a given sample for this signal represents the | |
127 | * signal itself. This is relevant for compound signals like logic, | |
128 | * rather meaningless for everything else but provided in case there | |
129 | * is a conversion active that provides a digital signal using bit #0. | |
130 | */ | |
131 | unsigned int logic_bit_index() const; | |
132 | ||
bf0edd2b SA |
133 | /** |
134 | * Gets the name of this signal. | |
135 | */ | |
136 | QString name() const; | |
137 | ||
050b5a6c SA |
138 | /** |
139 | * Gets the internal name of this signal, i.e. how the device calls it. | |
140 | */ | |
141 | QString internal_name() const; | |
142 | ||
b5d20c6d SA |
143 | /** |
144 | * Produces a string for this signal that can be used for display, | |
145 | * i.e. it contains one or both of the signal/internal names. | |
146 | */ | |
147 | QString display_name() const; | |
148 | ||
bf0edd2b SA |
149 | /** |
150 | * Sets the name of the signal. | |
151 | */ | |
152 | virtual void set_name(QString name); | |
153 | ||
154 | /** | |
641574bc | 155 | * Get the color of the signal. |
bf0edd2b | 156 | */ |
641574bc | 157 | QColor color() const; |
bf0edd2b SA |
158 | |
159 | /** | |
641574bc | 160 | * Set the color of the signal. |
bf0edd2b | 161 | */ |
641574bc | 162 | void set_color(QColor color); |
bf0edd2b SA |
163 | |
164 | /** | |
641574bc | 165 | * Get the background color of the signal. |
bf0edd2b | 166 | */ |
641574bc | 167 | QColor bgcolor() const; |
bf0edd2b | 168 | |
cbd2a2de SA |
169 | /** |
170 | * Sets the internal data object. | |
171 | */ | |
6f925ba9 | 172 | void set_data(shared_ptr<pv::data::SignalData> data); |
cbd2a2de SA |
173 | |
174 | /** | |
175 | * Get the internal data as analog data object in case of analog type. | |
176 | */ | |
6f925ba9 | 177 | shared_ptr<pv::data::Analog> analog_data() const; |
cbd2a2de SA |
178 | |
179 | /** | |
180 | * Get the internal data as logic data object in case of logic type. | |
181 | */ | |
6f925ba9 | 182 | shared_ptr<pv::data::Logic> logic_data() const; |
cbd2a2de | 183 | |
558ad6ce SA |
184 | /** |
185 | * Determines whether a given segment is complete (i.e. end-of-frame has | |
186 | * been seen). It only considers the original data, not the converted data. | |
187 | */ | |
188 | bool segment_is_complete(uint32_t segment_id) const; | |
189 | ||
d13d95b3 SA |
190 | /** |
191 | * Determines whether this signal has any sample data at all. | |
192 | */ | |
193 | bool has_samples() const; | |
194 | ||
06b6ce26 SA |
195 | /** |
196 | * Queries the kind of conversion performed on this channel. | |
197 | */ | |
198 | ConversionType get_conversion_type() const; | |
199 | ||
12ea3616 SA |
200 | /** |
201 | * Changes the kind of conversion performed on this channel. | |
52c900ac SA |
202 | * |
203 | * Restarts the conversion. | |
12ea3616 SA |
204 | */ |
205 | void set_conversion_type(ConversionType t); | |
206 | ||
52c900ac SA |
207 | /** |
208 | * Returns all currently known conversion options | |
209 | */ | |
210 | map<QString, QVariant> get_conversion_options() const; | |
211 | ||
212 | /** | |
213 | * Sets the value of a particular conversion option | |
214 | * Note: it is not checked whether the option is valid for the | |
215 | * currently conversion. If it's not, it will be silently ignored. | |
216 | * | |
217 | * Does not restart the conversion. | |
218 | * | |
219 | * @return true if the value is different from before, false otherwise | |
220 | */ | |
221 | bool set_conversion_option(QString key, QVariant value); | |
222 | ||
223 | /** | |
224 | * Returns the threshold(s) used for conversions, if applicable. | |
225 | * The resulting thresholds are given for the chosen conversion, so you | |
226 | * can query thresholds also for conversions which aren't currently active. | |
227 | * | |
228 | * If you want the thresholds for the currently active conversion, | |
229 | * call it either with NoConversion or no parameter. | |
230 | * | |
231 | * @param t the type of conversion to obtain the thresholds for, leave | |
232 | * empty or use NoConversion if you want to query the currently | |
233 | * used conversion | |
234 | * | |
235 | * @param always_custom ignore the currently selected preset and always | |
236 | * return the custom values for this conversion, using 0 if those | |
237 | * aren't set | |
238 | * | |
239 | * @return a list of threshold(s) used by the chosen conversion | |
240 | */ | |
241 | vector<double> get_conversion_thresholds( | |
242 | const ConversionType t = NoConversion, const bool always_custom=false) const; | |
243 | ||
244 | /** | |
245 | * Provides all conversion presets available for the currently active | |
246 | * conversion. | |
247 | * | |
248 | * @return a list of description/ID pairs for each preset | |
249 | */ | |
250 | vector<pair<QString, int> > get_conversion_presets() const; | |
251 | ||
252 | /** | |
253 | * Determines the ID of the currently used conversion preset, which is only | |
254 | * valid for the currently available conversion presets. It is therefore | |
255 | * suggested to call @ref get_conversion_presets right before calling this. | |
256 | * | |
257 | * @return the ID of the currently used conversion preset. -1 if no preset | |
258 | * is used. In that case, a user setting is used instead. | |
259 | */ | |
f0f9c856 | 260 | ConversionPreset get_current_conversion_preset() const; |
52c900ac SA |
261 | |
262 | /** | |
263 | * Sets the conversion preset to be used. | |
264 | * | |
265 | * Does not restart the conversion. | |
266 | * | |
267 | * @param id the id of the preset to use | |
268 | */ | |
f0f9c856 | 269 | void set_conversion_preset(ConversionPreset id); |
52c900ac | 270 | |
bb7dd726 | 271 | #ifdef ENABLE_DECODE |
47747218 | 272 | bool is_decode_signal() const; |
bb7dd726 | 273 | #endif |
cbd2a2de | 274 | |
47747218 | 275 | virtual void save_settings(QSettings &settings) const; |
6de38b17 | 276 | |
47747218 | 277 | virtual void restore_settings(QSettings &settings); |
6de38b17 | 278 | |
932bc246 | 279 | void start_conversion(bool delayed_start=false); |
52c900ac | 280 | |
12ea3616 | 281 | private: |
ccccb914 SA |
282 | bool conversion_is_a2l() const; |
283 | ||
12ea3616 | 284 | uint8_t convert_a2l_threshold(float threshold, float value); |
5d9fe823 SA |
285 | uint8_t convert_a2l_schmitt_trigger(float lo_thr, float hi_thr, |
286 | float value, uint8_t &state); | |
12ea3616 | 287 | |
784f6c75 SA |
288 | void convert_single_segment_range(AnalogSegment *asegment, |
289 | LogicSegment *lsegment, uint64_t start_sample, uint64_t end_sample); | |
63253d72 SA |
290 | void convert_single_segment(pv::data::AnalogSegment *asegment, |
291 | pv::data::LogicSegment *lsegment); | |
292 | void conversion_thread_proc(); | |
27a3f09b | 293 | |
27a3f09b | 294 | void stop_conversion(); |
12ea3616 | 295 | |
bf0edd2b SA |
296 | Q_SIGNALS: |
297 | void enabled_changed(const bool &value); | |
298 | ||
299 | void name_changed(const QString &name); | |
300 | ||
641574bc | 301 | void color_changed(const QColor &color); |
bf0edd2b | 302 | |
12ea3616 SA |
303 | void conversion_type_changed(const ConversionType t); |
304 | ||
eae3bbbb SA |
305 | void samples_cleared(); |
306 | ||
7f894d95 | 307 | void samples_added(uint64_t segment_id, uint64_t start_sample, |
eae3bbbb SA |
308 | uint64_t end_sample); |
309 | ||
c6d9cf65 SA |
310 | void min_max_changed(float min, float max); |
311 | ||
12ea3616 SA |
312 | private Q_SLOTS: |
313 | void on_samples_cleared(); | |
314 | ||
315 | void on_samples_added(QObject* segment, uint64_t start_sample, | |
316 | uint64_t end_sample); | |
317 | ||
8e15445c SA |
318 | void on_min_max_changed(float min, float max); |
319 | ||
12ea3616 SA |
320 | void on_capture_state_changed(int state); |
321 | ||
932bc246 SA |
322 | void on_delayed_conversion_start(); |
323 | ||
ad908057 | 324 | protected: |
6f925ba9 | 325 | shared_ptr<sigrok::Channel> channel_; |
472a80c5 | 326 | ChannelType channel_type_; |
6f925ba9 | 327 | shared_ptr<pv::data::SignalData> data_; |
12ea3616 | 328 | shared_ptr<pv::data::SignalData> converted_data_; |
06b6ce26 | 329 | ConversionType conversion_type_; |
52c900ac SA |
330 | map<QString, QVariant> conversion_options_; |
331 | ||
332 | float min_value_, max_value_; | |
cbd2a2de | 333 | |
12ea3616 | 334 | std::thread conversion_thread_; |
27a3f09b SA |
335 | atomic<bool> conversion_interrupt_; |
336 | mutex conversion_input_mutex_; | |
337 | condition_variable conversion_input_cond_; | |
932bc246 | 338 | QTimer delayed_conversion_starter_; |
12ea3616 | 339 | |
050b5a6c | 340 | QString internal_name_, name_; |
641574bc | 341 | QColor color_, bgcolor_; |
bf0edd2b SA |
342 | }; |
343 | ||
344 | } // namespace data | |
345 | } // namespace pv | |
346 | ||
347 | #endif // PULSEVIEW_PV_DATA_SIGNALBASE_HPP |