]>
Commit | Line | Data |
---|---|---|
1 | /* | |
2 | * This file is part of the PulseView project. | |
3 | * | |
4 | * Copyright (C) 2020 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 | #include <limits> | |
21 | ||
22 | #include <QDebug> | |
23 | ||
24 | #include "mathsignal.hpp" | |
25 | ||
26 | #include <extdef.h> | |
27 | #include <pv/globalsettings.hpp> | |
28 | #include <pv/session.hpp> | |
29 | #include <pv/data/analogsegment.hpp> | |
30 | #include <pv/data/signalbase.hpp> | |
31 | ||
32 | using std::dynamic_pointer_cast; | |
33 | using std::make_shared; | |
34 | using std::min; | |
35 | using std::unique_lock; | |
36 | ||
37 | namespace pv { | |
38 | namespace data { | |
39 | ||
40 | #define MATH_ERR_NONE 0 | |
41 | #define MATH_ERR_EMPTY_EXPR 1 | |
42 | #define MATH_ERR_EXPRESSION 2 | |
43 | #define MATH_ERR_INVALID_SIGNAL 3 | |
44 | #define MATH_ERR_ENABLE 4 | |
45 | ||
46 | const int64_t MathSignal::ChunkLength = 256 * 1024; | |
47 | ||
48 | ||
49 | template<typename T> | |
50 | struct fnc_sample : public exprtk::igeneric_function<T> | |
51 | { | |
52 | typedef typename exprtk::igeneric_function<T>::parameter_list_t parameter_list_t; | |
53 | typedef typename exprtk::igeneric_function<T>::generic_type generic_type; | |
54 | typedef typename generic_type::scalar_view scalar_t; | |
55 | typedef typename generic_type::string_view string_t; | |
56 | ||
57 | fnc_sample(MathSignal& owner) : | |
58 | exprtk::igeneric_function<T>("ST"), // Require channel name and sample number | |
59 | owner_(owner), | |
60 | sig_data(nullptr) | |
61 | { | |
62 | } | |
63 | ||
64 | T operator()(parameter_list_t parameters) | |
65 | { | |
66 | const string_t exprtk_sig_name = string_t(parameters[0]); | |
67 | const scalar_t exprtk_sample_num = scalar_t(parameters[1]); | |
68 | ||
69 | const std::string str_sig_name = to_str(exprtk_sig_name); | |
70 | const double sample_num = exprtk_sample_num(); | |
71 | ||
72 | if (sample_num < 0) | |
73 | return 0; | |
74 | ||
75 | if (!sig_data) | |
76 | sig_data = owner_.signal_from_name(str_sig_name); | |
77 | ||
78 | if (!sig_data) | |
79 | // There doesn't actually exist a signal with that name | |
80 | return 0; | |
81 | ||
82 | owner_.update_signal_sample(sig_data, current_segment, sample_num); | |
83 | ||
84 | return T(sig_data->sample_value); | |
85 | } | |
86 | ||
87 | MathSignal& owner_; | |
88 | uint32_t current_segment; | |
89 | signal_data* sig_data; | |
90 | }; | |
91 | ||
92 | ||
93 | MathSignal::MathSignal(pv::Session &session) : | |
94 | SignalBase(nullptr, SignalBase::MathChannel), | |
95 | session_(session), | |
96 | use_custom_sample_rate_(false), | |
97 | use_custom_sample_count_(false), | |
98 | expression_(""), | |
99 | error_type_(MATH_ERR_NONE), | |
100 | exprtk_unknown_symbol_table_(nullptr), | |
101 | exprtk_symbol_table_(nullptr), | |
102 | exprtk_expression_(nullptr), | |
103 | exprtk_parser_(nullptr), | |
104 | fnc_sample_(nullptr) | |
105 | { | |
106 | uint32_t sig_idx = session_.get_next_signal_index(MathChannel); | |
107 | set_name(QString(tr("Math%1")).arg(sig_idx)); | |
108 | set_color(AnalogSignalColors[(sig_idx - 1) % countof(AnalogSignalColors)]); | |
109 | ||
110 | set_data(std::make_shared<data::Analog>()); | |
111 | ||
112 | connect(&session_, SIGNAL(capture_state_changed(int)), | |
113 | this, SLOT(on_capture_state_changed(int))); | |
114 | } | |
115 | ||
116 | MathSignal::~MathSignal() | |
117 | { | |
118 | reset_generation(); | |
119 | } | |
120 | ||
121 | void MathSignal::save_settings(QSettings &settings) const | |
122 | { | |
123 | SignalBase::save_settings(settings); | |
124 | ||
125 | settings.setValue("expression", expression_); | |
126 | ||
127 | settings.setValue("custom_sample_rate", (qulonglong)custom_sample_rate_); | |
128 | settings.setValue("custom_sample_count", (qulonglong)custom_sample_count_); | |
129 | settings.setValue("use_custom_sample_rate", use_custom_sample_rate_); | |
130 | settings.setValue("use_custom_sample_count", use_custom_sample_count_); | |
131 | } | |
132 | ||
133 | void MathSignal::restore_settings(QSettings &settings) | |
134 | { | |
135 | SignalBase::restore_settings(settings); | |
136 | ||
137 | if (settings.contains("expression")) | |
138 | expression_ = settings.value("expression").toString(); | |
139 | ||
140 | if (settings.contains("custom_sample_rate")) | |
141 | custom_sample_rate_ = settings.value("custom_sample_rate").toULongLong(); | |
142 | ||
143 | if (settings.contains("custom_sample_count")) | |
144 | custom_sample_count_ = settings.value("custom_sample_count").toULongLong(); | |
145 | ||
146 | if (settings.contains("use_custom_sample_rate")) | |
147 | use_custom_sample_rate_ = settings.value("use_custom_sample_rate").toBool(); | |
148 | ||
149 | if (settings.contains("use_custom_sample_count")) | |
150 | use_custom_sample_count_ = settings.value("use_custom_sample_count").toBool(); | |
151 | } | |
152 | ||
153 | QString MathSignal::get_expression() const | |
154 | { | |
155 | return expression_; | |
156 | } | |
157 | ||
158 | void MathSignal::set_expression(QString expression) | |
159 | { | |
160 | expression_ = expression; | |
161 | ||
162 | begin_generation(); | |
163 | } | |
164 | ||
165 | void MathSignal::set_error(uint8_t type, QString msg) | |
166 | { | |
167 | error_type_ = type; | |
168 | error_message_ = msg; | |
169 | // TODO Emulate noquote() | |
170 | qDebug().nospace() << name() << ": " << msg << "(Expression: '" + expression_ + "')"; | |
171 | ||
172 | error_message_changed(msg); | |
173 | } | |
174 | ||
175 | uint64_t MathSignal::get_working_sample_count(uint32_t segment_id) const | |
176 | { | |
177 | // The working sample count is the highest sample number for | |
178 | // which all used signals have data available, so go through all | |
179 | // channels and use the lowest overall sample count of the segment | |
180 | ||
181 | int64_t result = std::numeric_limits<int64_t>::max(); | |
182 | ||
183 | if (use_custom_sample_count_) | |
184 | // A custom sample count implies that only one segment will be created | |
185 | result = (segment_id == 0) ? custom_sample_count_ : 0; | |
186 | else { | |
187 | if (input_signals_.size() > 0) { | |
188 | for (auto input_signal : input_signals_) { | |
189 | const shared_ptr<SignalBase>& sb = input_signal.second.sb; | |
190 | ||
191 | shared_ptr<Analog> a = sb->analog_data(); | |
192 | auto analog_segments = a->analog_segments(); | |
193 | ||
194 | if (analog_segments.size() == 0) { | |
195 | result = 0; | |
196 | continue; | |
197 | } | |
198 | ||
199 | const uint32_t highest_segment_id = (analog_segments.size() - 1); | |
200 | if (segment_id > highest_segment_id) | |
201 | continue; | |
202 | ||
203 | const shared_ptr<AnalogSegment> segment = analog_segments.at(segment_id); | |
204 | result = min(result, (int64_t)segment->get_sample_count()); | |
205 | } | |
206 | } else | |
207 | result = session_.get_segment_sample_count(segment_id); | |
208 | } | |
209 | ||
210 | return result; | |
211 | } | |
212 | ||
213 | void MathSignal::update_completeness(uint32_t segment_id, uint64_t output_sample_count) | |
214 | { | |
215 | bool output_complete = true; | |
216 | ||
217 | if (input_signals_.size() > 0) { | |
218 | for (auto input_signal : input_signals_) { | |
219 | const shared_ptr<SignalBase>& sb = input_signal.second.sb; | |
220 | ||
221 | shared_ptr<Analog> a = sb->analog_data(); | |
222 | auto analog_segments = a->analog_segments(); | |
223 | ||
224 | if (analog_segments.size() == 0) { | |
225 | output_complete = false; | |
226 | continue; | |
227 | } | |
228 | ||
229 | const uint32_t highest_segment_id = (analog_segments.size() - 1); | |
230 | if (segment_id > highest_segment_id) { | |
231 | output_complete = false; | |
232 | continue; | |
233 | } | |
234 | ||
235 | const shared_ptr<AnalogSegment> segment = analog_segments.at(segment_id); | |
236 | if (!segment->is_complete()) { | |
237 | output_complete = false; | |
238 | continue; | |
239 | } | |
240 | ||
241 | if (output_sample_count < segment->get_sample_count()) | |
242 | output_complete = false; | |
243 | } | |
244 | } else { | |
245 | // We're done when we generated as many samples as the stopped session is long | |
246 | if ((session_.get_capture_state() != Session::Stopped) || | |
247 | (output_sample_count < session_.get_segment_sample_count(segment_id))) | |
248 | output_complete = false; | |
249 | } | |
250 | ||
251 | if (output_complete) | |
252 | analog_data()->analog_segments().at(segment_id)->set_complete(); | |
253 | } | |
254 | ||
255 | void MathSignal::reset_generation() | |
256 | { | |
257 | if (gen_thread_.joinable()) { | |
258 | gen_interrupt_ = true; | |
259 | gen_input_cond_.notify_one(); | |
260 | gen_thread_.join(); | |
261 | } | |
262 | ||
263 | data_->clear(); | |
264 | input_signals_.clear(); | |
265 | ||
266 | if (exprtk_parser_) { | |
267 | delete exprtk_parser_; | |
268 | exprtk_parser_ = nullptr; | |
269 | } | |
270 | ||
271 | if (exprtk_expression_) { | |
272 | delete exprtk_expression_; | |
273 | exprtk_expression_ = nullptr; | |
274 | } | |
275 | ||
276 | if (exprtk_symbol_table_) { | |
277 | delete exprtk_symbol_table_; | |
278 | exprtk_symbol_table_ = nullptr; | |
279 | } | |
280 | ||
281 | if (exprtk_unknown_symbol_table_) { | |
282 | delete exprtk_unknown_symbol_table_; | |
283 | exprtk_unknown_symbol_table_ = nullptr; | |
284 | } | |
285 | ||
286 | if (fnc_sample_) { | |
287 | delete fnc_sample_; | |
288 | fnc_sample_ = nullptr; | |
289 | } | |
290 | ||
291 | if (!error_message_.isEmpty()) { | |
292 | error_message_.clear(); | |
293 | error_type_ = MATH_ERR_NONE; | |
294 | // TODO Emulate noquote() | |
295 | qDebug().nospace() << name() << ": Error cleared"; | |
296 | } | |
297 | ||
298 | generation_chunk_size_ = ChunkLength; | |
299 | } | |
300 | ||
301 | void MathSignal::begin_generation() | |
302 | { | |
303 | reset_generation(); | |
304 | ||
305 | if (expression_.isEmpty()) { | |
306 | set_error(MATH_ERR_EMPTY_EXPR, tr("No expression defined, nothing to do")); | |
307 | return; | |
308 | } | |
309 | ||
310 | disconnect(this, SLOT(on_data_received())); | |
311 | disconnect(this, SLOT(on_enabled_changed())); | |
312 | ||
313 | fnc_sample_ = new fnc_sample<double>(*this); | |
314 | ||
315 | exprtk_unknown_symbol_table_ = new exprtk::symbol_table<double>(); | |
316 | ||
317 | exprtk_symbol_table_ = new exprtk::symbol_table<double>(); | |
318 | exprtk_symbol_table_->add_constant("T", 1 / session_.get_samplerate()); | |
319 | exprtk_symbol_table_->add_function("sample", *fnc_sample_); | |
320 | exprtk_symbol_table_->add_variable("t", exprtk_current_time_); | |
321 | exprtk_symbol_table_->add_variable("s", exprtk_current_sample_); | |
322 | exprtk_symbol_table_->add_constants(); | |
323 | ||
324 | exprtk_expression_ = new exprtk::expression<double>(); | |
325 | exprtk_expression_->register_symbol_table(*exprtk_unknown_symbol_table_); | |
326 | exprtk_expression_->register_symbol_table(*exprtk_symbol_table_); | |
327 | ||
328 | exprtk_parser_ = new exprtk::parser<double>(); | |
329 | exprtk_parser_->enable_unknown_symbol_resolver(); | |
330 | ||
331 | if (!exprtk_parser_->compile(expression_.toStdString(), *exprtk_expression_)) { | |
332 | QString error_details; | |
333 | size_t error_count = exprtk_parser_->error_count(); | |
334 | ||
335 | for (size_t i = 0; i < error_count; i++) { | |
336 | typedef exprtk::parser_error::type error_t; | |
337 | error_t error = exprtk_parser_->get_error(i); | |
338 | exprtk::parser_error::update_error(error, expression_.toStdString()); | |
339 | ||
340 | QString error_detail = tr("%1 at line %2, column %3: %4"); | |
341 | if ((error_count > 1) && (i < (error_count - 1))) | |
342 | error_detail += "\n"; | |
343 | ||
344 | error_details += error_detail \ | |
345 | .arg(exprtk::parser_error::to_str(error.mode).c_str()) \ | |
346 | .arg(error.line_no) \ | |
347 | .arg(error.column_no) \ | |
348 | .arg(error.diagnostic.c_str()); | |
349 | } | |
350 | set_error(MATH_ERR_EXPRESSION, error_details); | |
351 | } else { | |
352 | // Resolve unknown scalars to signals and add them to the input signal list | |
353 | vector<string> unknowns; | |
354 | exprtk_unknown_symbol_table_->get_variable_list(unknowns); | |
355 | for (string& unknown : unknowns) { | |
356 | signal_data* sig_data = signal_from_name(unknown); | |
357 | const shared_ptr<SignalBase> signal = (sig_data) ? (sig_data->sb) : nullptr; | |
358 | if (!signal || (!signal->analog_data())) { | |
359 | set_error(MATH_ERR_INVALID_SIGNAL, QString(tr("\"%1\" isn't a valid analog signal")) \ | |
360 | .arg(QString::fromStdString(unknown))); | |
361 | } else | |
362 | sig_data->ref = &(exprtk_unknown_symbol_table_->variable_ref(unknown)); | |
363 | } | |
364 | } | |
365 | ||
366 | QString disabled_signals; | |
367 | if (!all_input_signals_enabled(disabled_signals) && error_message_.isEmpty()) | |
368 | set_error(MATH_ERR_ENABLE, | |
369 | tr("No data will be generated as %1 must be enabled").arg(disabled_signals)); | |
370 | ||
371 | if (error_message_.isEmpty()) { | |
372 | // Connect to the session data notification if we have no input signals | |
373 | if (input_signals_.empty()) | |
374 | connect(&session_, SIGNAL(data_received()), | |
375 | this, SLOT(on_data_received())); | |
376 | ||
377 | gen_interrupt_ = false; | |
378 | gen_thread_ = std::thread(&MathSignal::generation_proc, this); | |
379 | } | |
380 | } | |
381 | ||
382 | uint64_t MathSignal::generate_samples(uint32_t segment_id, const uint64_t start_sample, | |
383 | const int64_t sample_count) | |
384 | { | |
385 | uint64_t count = 0; | |
386 | ||
387 | shared_ptr<Analog> analog = dynamic_pointer_cast<Analog>(data_); | |
388 | shared_ptr<AnalogSegment> segment = analog->analog_segments().at(segment_id); | |
389 | ||
390 | // Keep the math functions segment IDs in sync | |
391 | fnc_sample_->current_segment = segment_id; | |
392 | ||
393 | const double sample_rate = data_->get_samplerate(); | |
394 | ||
395 | exprtk_current_sample_ = start_sample; | |
396 | ||
397 | float *sample_data = new float[sample_count]; | |
398 | ||
399 | for (int64_t i = 0; i < sample_count; i++) { | |
400 | exprtk_current_time_ = exprtk_current_sample_ / sample_rate; | |
401 | ||
402 | for (auto& entry : input_signals_) { | |
403 | signal_data* sig_data = &(entry.second); | |
404 | update_signal_sample(sig_data, segment_id, exprtk_current_sample_); | |
405 | } | |
406 | ||
407 | double value = exprtk_expression_->value(); | |
408 | sample_data[i] = value; | |
409 | exprtk_current_sample_ += 1; | |
410 | count++; | |
411 | ||
412 | // If during the evaluation of the expression it was found that this | |
413 | // math signal itself is being accessed, the chunk size was reduced | |
414 | // to 1, which means we must stop after this sample we just generated | |
415 | if (generation_chunk_size_ == 1) | |
416 | break; | |
417 | } | |
418 | ||
419 | segment->append_interleaved_samples(sample_data, count, 1); | |
420 | ||
421 | delete[] sample_data; | |
422 | ||
423 | return count; | |
424 | } | |
425 | ||
426 | void MathSignal::generation_proc() | |
427 | { | |
428 | // Don't do anything until we have a valid sample rate | |
429 | do { | |
430 | if (use_custom_sample_rate_) | |
431 | data_->set_samplerate(custom_sample_rate_); | |
432 | else | |
433 | data_->set_samplerate(session_.get_samplerate()); | |
434 | ||
435 | if (data_->get_samplerate() == 1) { | |
436 | unique_lock<mutex> gen_input_lock(input_mutex_); | |
437 | gen_input_cond_.wait(gen_input_lock); | |
438 | } | |
439 | } while ((!gen_interrupt_) && (data_->get_samplerate() == 1)); | |
440 | ||
441 | if (gen_interrupt_) | |
442 | return; | |
443 | ||
444 | uint32_t segment_id = 0; | |
445 | shared_ptr<Analog> analog = analog_data(); | |
446 | ||
447 | // Create initial analog segment | |
448 | shared_ptr<AnalogSegment> output_segment = | |
449 | make_shared<AnalogSegment>(*analog.get(), segment_id, analog->get_samplerate()); | |
450 | analog->push_segment(output_segment); | |
451 | ||
452 | // Create analog samples | |
453 | do { | |
454 | const uint64_t input_sample_count = get_working_sample_count(segment_id); | |
455 | const uint64_t output_sample_count = output_segment->get_sample_count(); | |
456 | ||
457 | const uint64_t samples_to_process = | |
458 | (input_sample_count > output_sample_count) ? | |
459 | (input_sample_count - output_sample_count) : 0; | |
460 | ||
461 | // Process the samples if necessary... | |
462 | if (samples_to_process > 0) { | |
463 | uint64_t processed_samples = 0; | |
464 | do { | |
465 | const uint64_t start_sample = output_sample_count + processed_samples; | |
466 | uint64_t sample_count = | |
467 | min(samples_to_process - processed_samples, generation_chunk_size_); | |
468 | ||
469 | sample_count = generate_samples(segment_id, start_sample, sample_count); | |
470 | processed_samples += sample_count; | |
471 | ||
472 | // Notify consumers of this signal's data | |
473 | samples_added(segment_id, start_sample, start_sample + processed_samples); | |
474 | } while (!gen_interrupt_ && (processed_samples < samples_to_process)); | |
475 | } | |
476 | ||
477 | update_completeness(segment_id, output_sample_count); | |
478 | ||
479 | if (output_segment->is_complete() && (segment_id < session_.get_highest_segment_id())) { | |
480 | // Process next segment | |
481 | segment_id++; | |
482 | ||
483 | output_segment = | |
484 | make_shared<AnalogSegment>(*analog.get(), segment_id, analog->get_samplerate()); | |
485 | analog->push_segment(output_segment); | |
486 | } | |
487 | ||
488 | if (!gen_interrupt_ && (samples_to_process == 0)) { | |
489 | // Wait for more input | |
490 | unique_lock<mutex> gen_input_lock(input_mutex_); | |
491 | gen_input_cond_.wait(gen_input_lock); | |
492 | } | |
493 | } while (!gen_interrupt_); | |
494 | } | |
495 | ||
496 | signal_data* MathSignal::signal_from_name(const std::string& name) | |
497 | { | |
498 | // If the expression contains the math signal itself, we must add every sample to | |
499 | // the output segment immediately so that it can be accessed | |
500 | const QString sig_name = QString::fromStdString(name); | |
501 | if (sig_name == this->name()) | |
502 | generation_chunk_size_ = 1; | |
503 | ||
504 | // Look up signal in the map and if it doesn't exist yet, add it for future use | |
505 | ||
506 | auto element = input_signals_.find(name); | |
507 | ||
508 | if (element != input_signals_.end()) { | |
509 | return &(element->second); | |
510 | } else { | |
511 | const vector< shared_ptr<SignalBase> > signalbases = session_.signalbases(); | |
512 | ||
513 | for (const shared_ptr<SignalBase>& sb : signalbases) | |
514 | if (sb->name() == sig_name) { | |
515 | if (!sb->analog_data()) | |
516 | continue; | |
517 | ||
518 | connect(sb->analog_data().get(), SIGNAL(samples_added(SharedPtrToSegment, uint64_t, uint64_t)), | |
519 | this, SLOT(on_data_received())); | |
520 | connect(sb->analog_data().get(), SIGNAL(segment_completed()), | |
521 | this, SLOT(on_data_received())); | |
522 | ||
523 | connect(sb.get(), SIGNAL(enabled_changed(bool)), | |
524 | this, SLOT(on_enabled_changed())); | |
525 | ||
526 | return &(input_signals_.insert({name, signal_data(sb)}).first->second); | |
527 | } | |
528 | } | |
529 | ||
530 | // If we reach this point, no valid signal was found with the supplied name | |
531 | if (error_type_ == MATH_ERR_NONE) | |
532 | set_error(MATH_ERR_INVALID_SIGNAL, QString(tr("\"%1\" isn't a valid analog signal")) \ | |
533 | .arg(QString::fromStdString(name))); | |
534 | ||
535 | return nullptr; | |
536 | } | |
537 | ||
538 | void MathSignal::update_signal_sample(signal_data* sig_data, uint32_t segment_id, uint64_t sample_num) | |
539 | { | |
540 | assert(sig_data); | |
541 | ||
542 | // Update the value only if a different sample is requested | |
543 | if (sig_data->sample_num == sample_num) | |
544 | return; | |
545 | ||
546 | assert(sig_data->sb); | |
547 | const shared_ptr<pv::data::Analog> analog = sig_data->sb->analog_data(); | |
548 | assert(analog); | |
549 | ||
550 | assert(segment_id < analog->analog_segments().size()); | |
551 | ||
552 | const shared_ptr<AnalogSegment> segment = analog->analog_segments().at(segment_id); | |
553 | ||
554 | sig_data->sample_num = sample_num; | |
555 | ||
556 | if (sample_num < segment->get_sample_count()) | |
557 | sig_data->sample_value = segment->get_sample(sample_num); | |
558 | else | |
559 | sig_data->sample_value = 0; | |
560 | ||
561 | // We only have a reference if this signal is used as a scalar; | |
562 | // if it's used by a function, it's null | |
563 | if (sig_data->ref) | |
564 | *(sig_data->ref) = sig_data->sample_value; | |
565 | } | |
566 | ||
567 | bool MathSignal::all_input_signals_enabled(QString &disabled_signals) const | |
568 | { | |
569 | bool all_enabled = true; | |
570 | ||
571 | disabled_signals.clear(); | |
572 | ||
573 | for (auto input_signal : input_signals_) { | |
574 | const shared_ptr<SignalBase>& sb = input_signal.second.sb; | |
575 | ||
576 | if (!sb->enabled()) { | |
577 | all_enabled = false; | |
578 | disabled_signals += disabled_signals.isEmpty() ? | |
579 | sb->name() : ", " + sb->name(); | |
580 | } | |
581 | } | |
582 | ||
583 | return all_enabled; | |
584 | } | |
585 | ||
586 | void MathSignal::on_capture_state_changed(int state) | |
587 | { | |
588 | if (state == Session::Running) | |
589 | begin_generation(); | |
590 | ||
591 | // Make sure we don't miss any input samples, just in case | |
592 | if (state == Session::Stopped) | |
593 | gen_input_cond_.notify_one(); | |
594 | } | |
595 | ||
596 | void MathSignal::on_data_received() | |
597 | { | |
598 | gen_input_cond_.notify_one(); | |
599 | } | |
600 | ||
601 | void MathSignal::on_enabled_changed() | |
602 | { | |
603 | QString disabled_signals; | |
604 | if (!all_input_signals_enabled(disabled_signals) && | |
605 | ((error_type_ == MATH_ERR_NONE) || (error_type_ == MATH_ERR_ENABLE))) | |
606 | set_error(MATH_ERR_ENABLE, | |
607 | tr("No data will be generated as %1 must be enabled").arg(disabled_signals)); | |
608 | else if (disabled_signals.isEmpty() && (error_type_ == MATH_ERR_ENABLE)) { | |
609 | error_type_ = MATH_ERR_NONE; | |
610 | error_message_.clear(); | |
611 | } | |
612 | } | |
613 | ||
614 | } // namespace data | |
615 | } // namespace pv |