2 * This file is part of the PulseView project.
4 * Copyright (C) 2020 Soeren Apel <soeren@apelpie.net>
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.
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.
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/>.
20 #ifndef PULSEVIEW_PV_DATA_MATHSIGNAL_HPP
21 #define PULSEVIEW_PV_DATA_MATHSIGNAL_HPP
25 #include <pv/exprtk.hpp>
26 #include <pv/util.hpp>
27 #include <pv/data/analog.hpp>
28 #include <pv/data/signalbase.hpp>
31 using std::condition_variable;
33 using std::shared_ptr;
42 class MathSignal : public SignalBase
45 Q_PROPERTY(QString expression READ get_expression WRITE set_expression NOTIFY expression_changed)
46 Q_PROPERTY(QString error_message READ error_message)
49 static const int64_t ChunkLength;
52 MathSignal(pv::Session &session);
53 virtual ~MathSignal();
55 virtual void save_settings(QSettings &settings) const;
56 virtual void restore_settings(QSettings &settings);
58 QString error_message() const;
60 QString get_expression() const;
61 void set_expression(QString expression);
64 void set_error_message(QString msg);
67 * Returns the number of samples that can be worked on,
68 * i.e. the number of samples where samples are available
69 * for all connected channels.
70 * If the math signal uses no input channels, this is the
71 * number of samples in the session.
73 uint64_t get_working_sample_count(uint32_t segment_id) const;
75 void reset_generation();
76 void begin_generation();
78 void generate_samples(uint32_t segment_id, const uint64_t start_sample,
79 const int64_t sample_count);
80 void generation_proc();
83 void samples_cleared();
85 void samples_added(uint64_t segment_id, uint64_t start_sample,
88 void min_max_changed(float min, float max);
90 void expression_changed(QString expression);
93 void on_capture_state_changed(int state);
94 void on_data_received();
97 pv::Session &session_;
99 uint64_t custom_sample_rate_;
100 uint64_t custom_sample_count_;
101 bool use_custom_sample_rate_, use_custom_sample_count_;
102 vector< shared_ptr<SignalBase>> input_signals_;
106 QString error_message_;
108 mutable mutex input_mutex_;
109 mutable condition_variable gen_input_cond_;
111 std::thread gen_thread_;
112 atomic<bool> gen_interrupt_;
114 exprtk::symbol_table<double> *exprtk_symbol_table_;
115 exprtk::expression<double> *exprtk_expression_;
116 exprtk::parser<double> *exprtk_parser_;
117 double exprtk_current_time_, exprtk_current_sample_;
123 #endif // PULSEVIEW_PV_DATA_MATHSIGNAL_HPP