]> sigrok.org Git - pulseview.git/blobdiff - pv/data/signalbase.hpp
Implement logic data muxer thread
[pulseview.git] / pv / data / signalbase.hpp
index ca3cd5c47c8b0489490c65a66905cc0c000c3a47..322bdf48e8c3a026d2156aa6ab75e05b024e9935 100644 (file)
  * GNU General Public License for more details.
  *
  * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
+ * along with this program; if not, see <http://www.gnu.org/licenses/>.
  */
 
 #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>
 #include <QString>
 
 #include <libsigrokcxx/libsigrokcxx.hpp>
 
+using std::atomic;
+using std::condition_variable;
+using std::mutex;
+using std::shared_ptr;
 
 namespace sigrok {
 class Channel;
-class ChannelType;
 }
 
 namespace pv {
 namespace data {
 
 class Analog;
+class DecoderStack;
 class Logic;
 class SignalData;
 
@@ -45,18 +53,34 @@ class SignalBase : public QObject
 {
        Q_OBJECT
 
+public:
+       enum ChannelType {
+               AnalogChannel = 1,
+               LogicChannel,
+               DecodeChannel,
+               A2LChannel,  // Analog converted to logic, joint representation
+               MathChannel
+       };
+
+       enum ConversionType {
+               NoConversion = 0,
+               A2LConversionByTreshold = 1,
+               A2LConversionBySchmittTrigger = 2
+       };
+
 private:
        static const int ColourBGAlpha;
+       static const uint64_t ConversionBlockSize;
 
 public:
-       SignalBase(std::shared_ptr<sigrok::Channel> channel);
-       virtual ~SignalBase() {}
+       SignalBase(shared_ptr<sigrok::Channel> channel, ChannelType channel_type);
+       virtual ~SignalBase();
 
 public:
        /**
         * Returns the underlying SR channel.
         */
-       std::shared_ptr<sigrok::Channel> channel() const;
+       shared_ptr<sigrok::Channel> channel() const;
 
        /**
         * Returns enabled status of this channel.
@@ -72,18 +96,32 @@ public:
        /**
         * Gets the type of this channel.
         */
-       const sigrok::ChannelType *type() const;
+       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.
         */
        QString name() const;
 
+       /**
+        * Gets the internal name of this signal, i.e. how the device calls it.
+        */
+       QString internal_name() const;
+
        /**
         * Sets the name of the signal.
         */
@@ -107,18 +145,40 @@ public:
        /**
         * Sets the internal data object.
         */
-       void set_data(std::shared_ptr<pv::data::SignalData> data);
+       void set_data(shared_ptr<pv::data::SignalData> data);
 
        /**
         * Get the internal data as analog data object in case of analog type.
         */
-       std::shared_ptr<pv::data::Analog> analog_data() const;
+       shared_ptr<pv::data::Analog> analog_data() const;
 
        /**
         * Get the internal data as logic data object in case of logic type.
         */
-       std::shared_ptr<pv::data::Logic> logic_data() const;
+       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
 
+       virtual void save_settings(QSettings &settings) const;
+
+       virtual void restore_settings(QSettings &settings);
+
+private:
+       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);
@@ -127,11 +187,34 @@ Q_SIGNALS:
 
        void colour_changed(const QColor &colour);
 
-private:
-       std::shared_ptr<sigrok::Channel> channel_;
-       std::shared_ptr<pv::data::SignalData> data_;
+       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_;
+
+       std::thread conversion_thread_;
+       atomic<bool> conversion_interrupt_;
+       mutex conversion_input_mutex_;
+       condition_variable conversion_input_cond_;
 
-       QString name_;
+       QString internal_name_, name_;
        QColor colour_, bgcolour_;
 };