LCOV - code coverage report
Current view: top level - include/qtpokit - dsoservice.h (source / functions) Hit Total Coverage
Project: QtPokit Lines: 4 4 100.0 %
Version: Functions: 0 0 -

          Line data    Source code
       1             : // SPDX-FileCopyrightText: 2022-2023 Paul Colby <git@colby.id.au>
       2             : // SPDX-License-Identifier: LGPL-3.0-or-later
       3             : 
       4             : /*!
       5             :  * \file
       6             :  * Declares the DsoService class.
       7             :  */
       8             : 
       9             : #ifndef QTPOKIT_DSOSERVICE_H
      10             : #define QTPOKIT_DSOSERVICE_H
      11             : 
      12             : #include "abstractpokitservice.h"
      13             : 
      14             : #include <QBluetoothAddress>
      15             : #include <QBluetoothUuid>
      16             : #include <QVersionNumber>
      17             : 
      18             : QTPOKIT_BEGIN_NAMESPACE
      19             : 
      20             : class DsoServicePrivate;
      21             : 
      22             : class QTPOKIT_EXPORT DsoService : public AbstractPokitService
      23             : {
      24        3638 :     Q_OBJECT
      25             : 
      26             : public:
      27             :     static const QBluetoothUuid serviceUuid;
      28             : 
      29             :     struct QTPOKIT_EXPORT CharacteristicUuids {
      30             :         static const QBluetoothUuid settings;
      31             :         static const QBluetoothUuid metadata;
      32             :         static const QBluetoothUuid reading;
      33             :     };
      34             : 
      35             :     enum class Command : quint8 {
      36             :         FreeRunning        = 0, ///< Run free, without waiting for edge triggers.
      37             :         RisingEdgeTrigger  = 1, ///< Trigger on a rising edge.
      38             :         FallingEdgeTrigger = 2, ///< Trigger on a falling edge.
      39             :         ResendData         = 3  ///< Resend the last acquired data.
      40             :     };
      41             : 
      42             :     enum class Mode : quint8 {
      43             :         Idle        = 0, ///< Make device idle.
      44             :         DcVoltage   = 1, ///< Measure DC voltage.
      45             :         AcVoltage   = 2, ///< Measure AC voltage.
      46             :         DcCurrent   = 3, ///< Measure DC current.
      47             :         AcCurrent   = 4, ///< Measure AC current.
      48             :     };
      49             :     static QString toString(const Mode &mode);
      50             : 
      51             :     enum class VoltageRange : quint8 {
      52             :         _0_to_300mV  = 0,  ///< 0 to 300mV.
      53             :         _300mV_to_2V = 1,  ///< 300mV to 2V.
      54             :         _2V_to_6V    = 2,  ///< 2V to 6V.
      55             :         _6V_to_12V   = 3,  ///< 6V to 12V.
      56             :         _12V_to_30V  = 4,  ///< 12V to 30V.
      57             :         _30V_to_60V  = 5,  ///< 30V to 60V.
      58             :         /// \todo Pokit Pro supports up to 600V.
      59             :     };
      60             :     static QString toString(const VoltageRange &range);
      61             :     static QVariant minValue(const VoltageRange &range);
      62             :     static QVariant maxValue(const VoltageRange &range);
      63             : 
      64             :     enum class CurrentRange : quint8 {
      65             :         _0_to_10mA      = 0,  ///< 0 to 10mA.
      66             :         _10mA_to_30mA   = 1,  ///< 10mA to 30mA.
      67             :         _30mA_to_150mA  = 2,  ///< 30mA to 150mA.
      68             :         _150mA_to_300mA = 3,  ///< 150mA to 300mA.
      69             :         _300mA_to_3A    = 4,  ///< 300mA to 3A.
      70             :         /// \todo Pokit Pro supports up to 10A.
      71             :     };
      72             :     static QString toString(const CurrentRange &range);
      73             :     static QVariant minValue(const CurrentRange &range);
      74             :     static QVariant maxValue(const CurrentRange &range);
      75             : 
      76             :     union QTPOKIT_EXPORT Range {
      77             :         VoltageRange voltageRange; ///< Range when in AC/DC voltage mode.
      78             :         CurrentRange currentRange; ///< Range when in AC/DC current mode.
      79             :         Range();
      80             :         Range(const VoltageRange range);
      81             :         Range(const CurrentRange range);
      82             :     };
      83             :     static QString toString(const Range &range, const Mode &mode);
      84             : 
      85          17 :     struct Settings {
      86             :         Command command;         ///< Custom operation request.
      87             :         float triggerLevel;      ///< Trigger threshold level in Volts or Amps, depending on #mode.
      88             :         Mode mode;               ///< Desired operation mode.
      89             :         Range range;             ///< Desired range.
      90             :         quint32 samplingWindow;  ///< Desired sampling window in microseconds.
      91             :         quint16 numberOfSamples; ///< Desired number of samples to acquire.
      92             :     };
      93             : 
      94             :     enum class DsoStatus : quint8 {
      95             :         Done       = 0,  ///< Sampling has completed.
      96             :         Sampling   = 1,  ///< Actively sampling.
      97             :         Error      = 255 ///< An error has occurred.
      98             :     };
      99             : 
     100        1530 :     struct Metadata {
     101             :         DsoStatus status;        ///< Current DSO status.
     102             :         float scale;             ///< Scale to apply to read samples.
     103             :         Mode mode;               ///< Operation mode used during last acquisition.
     104             :         Range range;             ///< Range used during last acquisition.
     105             :         quint32 samplingWindow;  ///< Sampling window (microseconds) used during last acquisition.
     106             :         quint16 numberOfSamples; ///< Number of samples acquired (1 to 8192).
     107             :         quint32 samplingRate;    ///< Sampling rate  used during last acquisition (1 to 1MHz).
     108             :     };
     109             : 
     110             :     typedef QVector<qint16> Samples;
     111             : 
     112             :     DsoService(QLowEnergyController * const pokitDevice, QObject * parent = nullptr);
     113             :     ~DsoService() override;
     114             : 
     115             :     bool readCharacteristics() override;
     116             :     bool readMetadataCharacteristic();
     117             : 
     118             :     // Settings characteristic (BLE write only).
     119             :     bool setSettings(const Settings &settings);
     120             :     bool startDso(const Settings &settings);
     121             :     bool fetchSamples();
     122             : 
     123             :     // Metadata characteristic (BLE read/notify).
     124             :     Metadata metadata() const;
     125             :     bool enableMetadataNotifications();
     126             :     bool disableMetadataNotifications();
     127             : 
     128             :     // Reading characteristic (BLE notify only).
     129             :     bool enableReadingNotifications();
     130             :     bool disableReadingNotifications();
     131             : 
     132             : signals:
     133             :     void settingsWritten();
     134             :     void metadataRead(const DsoService::Metadata &meta);
     135             :     void samplesRead(const DsoService::Samples &samples);
     136             : 
     137             : protected:
     138             :     /// \cond internal
     139             :     DsoService(DsoServicePrivate * const d, QObject * const parent);
     140             :     /// \endcond
     141             : 
     142             : private:
     143         255 :     Q_DECLARE_PRIVATE(DsoService)
     144             :     Q_DISABLE_COPY(DsoService)
     145             :     friend class TestDsoService;
     146             : };
     147             : 
     148             : QTPOKIT_EXPORT bool operator==(const DsoService::Range &lhs, const DsoService::Range &rhs);
     149             : QTPOKIT_EXPORT bool operator!=(const DsoService::Range &lhs, const DsoService::Range &rhs);
     150             : QTPOKIT_EXPORT bool operator< (const DsoService::Range &lhs, const DsoService::Range &rhs);
     151             : QTPOKIT_EXPORT bool operator> (const DsoService::Range &lhs, const DsoService::Range &rhs);
     152             : QTPOKIT_EXPORT bool operator<=(const DsoService::Range &lhs, const DsoService::Range &rhs);
     153             : QTPOKIT_EXPORT bool operator>=(const DsoService::Range &lhs, const DsoService::Range &rhs);
     154             : 
     155             : QTPOKIT_END_NAMESPACE
     156             : 
     157             : #endif // QTPOKIT_DSOSERVICE_H

Generated by: LCOV version 1.14