]> sigrok.org Git - pulseview.git/blobdiff - pv/data/signalbase.hpp
DecodeSignal: Provide conversion data container sooner
[pulseview.git] / pv / data / signalbase.hpp
index 4889d16acd4bc1ba75878cfe132e2d07b1202193..468a2032812cba3b7611f1d6cf5dcfa718fe0bc5 100644 (file)
 #ifndef PULSEVIEW_PV_DATA_SIGNALBASE_HPP
 #define PULSEVIEW_PV_DATA_SIGNALBASE_HPP
 
+#include <atomic>
+#include <condition_variable>
+#include <thread>
+
 #include <QColor>
 #include <QObject>
 #include <QSettings>
@@ -28,6 +32,9 @@
 
 #include <libsigrokcxx/libsigrokcxx.hpp>
 
+using std::atomic;
+using std::condition_variable;
+using std::mutex;
 using std::shared_ptr;
 
 namespace sigrok {
@@ -55,12 +62,19 @@ public:
                MathChannel
        };
 
+       enum ConversionType {
+               NoConversion = 0,
+               A2LConversionByTreshold = 1,
+               A2LConversionBySchmittTrigger = 2
+       };
+
 private:
        static const int ColourBGAlpha;
+       static const uint64_t ConversionBlockSize;
 
 public:
        SignalBase(shared_ptr<sigrok::Channel> channel, ChannelType channel_type);
-       virtual ~SignalBase() {}
+       virtual ~SignalBase();
 
 public:
        /**
@@ -85,10 +99,19 @@ public:
        ChannelType type() const;
 
        /**
-        * Gets the index number of this channel.
+        * Gets the index number of this channel, i.e. a unique ID assigned by
+        * the device driver.
         */
        unsigned int index() const;
 
+       /**
+        * Returns which bit of a given sample for this signal represents the
+        * signal itself. This is relevant for compound signals like logic,
+        * rather meaningless for everything else but provided in case there
+        * is a conversion active that provides a digital signal using bit #0.
+        */
+       unsigned int logic_bit_index() const;
+
        /**
         * Gets the name of this signal.
         */
@@ -134,17 +157,30 @@ public:
         */
        shared_ptr<pv::data::Logic> logic_data() const;
 
+       /**
+        * Changes the kind of conversion performed on this channel.
+        */
+       void set_conversion_type(ConversionType t);
+
 #ifdef ENABLE_DECODE
        bool is_decode_signal() const;
+#endif
 
-       shared_ptr<pv::data::DecoderStack> decoder_stack() const;
+       virtual void save_settings(QSettings &settings) const;
 
-       void set_decoder_stack(shared_ptr<pv::data::DecoderStack> decoder_stack);
-#endif
+       virtual void restore_settings(QSettings &settings);
 
-       void save_settings(QSettings &settings) const;
+private:
+       bool conversion_is_a2l() const;
 
-       void restore_settings(QSettings &settings);
+       uint8_t convert_a2l_threshold(float threshold, float value);
+       uint8_t convert_a2l_schmitt_trigger(float lo_thr, float hi_thr,
+               float value, uint8_t &state);
+
+       void conversion_thread_proc(QObject* segment);
+
+       void start_conversion();
+       void stop_conversion();
 
 Q_SIGNALS:
        void enabled_changed(const bool &value);
@@ -153,14 +189,32 @@ Q_SIGNALS:
 
        void colour_changed(const QColor &colour);
 
-private:
+       void conversion_type_changed(const ConversionType t);
+
+       void samples_cleared();
+
+       void samples_added(QObject* segment, uint64_t start_sample,
+               uint64_t end_sample);
+
+private Q_SLOTS:
+       void on_samples_cleared();
+
+       void on_samples_added(QObject* segment, uint64_t start_sample,
+               uint64_t end_sample);
+
+       void on_capture_state_changed(int state);
+
+protected:
        shared_ptr<sigrok::Channel> channel_;
        ChannelType channel_type_;
        shared_ptr<pv::data::SignalData> data_;
+       shared_ptr<pv::data::SignalData> converted_data_;
+       int conversion_type_;
 
-#ifdef ENABLE_DECODE
-       shared_ptr<pv::data::DecoderStack> decoder_stack_;
-#endif
+       std::thread conversion_thread_;
+       atomic<bool> conversion_interrupt_;
+       mutex conversion_input_mutex_;
+       condition_variable conversion_input_cond_;
 
        QString internal_name_, name_;
        QColor colour_, bgcolour_;