LCOV - code coverage report
Current view: top level - include/qtpokit - dsoservice.h (source / functions) Hit Total Coverage
Project: Dokit Lines: 2 2 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             : #include "pokitproducts.h"
      14             : 
      15             : #include <QBluetoothAddress>
      16             : #include <QBluetoothUuid>
      17             : #include <QVersionNumber>
      18             : 
      19             : QTPOKIT_BEGIN_NAMESPACE
      20             : 
      21             : class DsoServicePrivate;
      22             : 
      23             : class QTPOKIT_EXPORT DsoService : public AbstractPokitService
      24             : {
      25        2337 :     Q_OBJECT
      26             : 
      27             : public:
      28             :     /// UUID of the "DSO" service.
      29             :     static inline const QBluetoothUuid serviceUuid { QStringLiteral("1569801e-1425-4a7a-b617-a4f4ed719de6") };
      30             : 
      31             :     /// Characteristics available via the `DSO` service.
      32             :     struct QTPOKIT_EXPORT CharacteristicUuids {
      33             :         /// UUID of the `DSO` service's `Settings` characterstic.
      34             :         static inline const QBluetoothUuid settings { QStringLiteral("a81af1b6-b8b3-4244-8859-3da368d2be39") };
      35             : 
      36             :         /// UUID of the `DSO` service's `Metadata` characterstic.
      37             :         static inline const QBluetoothUuid metadata { QStringLiteral("970f00ba-f46f-4825-96a8-153a5cd0cda9") };
      38             : 
      39             :         /// UUID of the `DSO` service's `Reading` characterstic.
      40             :         static inline const QBluetoothUuid reading  { QStringLiteral("98e14f8e-536e-4f24-b4f4-1debfed0a99e") };
      41             :     };
      42             : 
      43             :     /// Values supported by the `Command` attribute of the `Settings` characteristic.
      44             :     enum class Command : quint8 {
      45             :         FreeRunning        = 0, ///< Run free, without waiting for edge triggers.
      46             :         RisingEdgeTrigger  = 1, ///< Trigger on a rising edge.
      47             :         FallingEdgeTrigger = 2, ///< Trigger on a falling edge.
      48             :         ResendData         = 3  ///< Resend the last acquired data.
      49             :     };
      50             : 
      51             :     /// Values supported by the `Mode` attribute of the `Settings` and `Metadata` characteristics.
      52             :     enum class Mode : quint8 {
      53             :         Idle        = 0, ///< Make device idle.
      54             :         DcVoltage   = 1, ///< Measure DC voltage.
      55             :         AcVoltage   = 2, ///< Measure AC voltage.
      56             :         DcCurrent   = 3, ///< Measure DC current.
      57             :         AcCurrent   = 4, ///< Measure AC current.
      58             :     };
      59             :     static QString toString(const Mode &mode);
      60             : 
      61             :     static QString toString(const PokitProduct product, const quint8 range, const Mode mode);
      62             :     QString toString(const quint8 range, const Mode mode) const;
      63             :     static QVariant maxValue(const PokitProduct product, const quint8 range, const Mode mode);
      64             :     QVariant maxValue(const quint8 range, const Mode mode) const;
      65             : 
      66             :     /// Attributes included in the `Settings` characterstic.
      67             :     struct Settings {
      68             :         Command command;         ///< Custom operation request.
      69             :         float triggerLevel;      ///< Trigger threshold level in Volts or Amps, depending on #mode.
      70             :         Mode mode;               ///< Desired operation mode.
      71             :         quint8 range;            ///< Desired range, eg settings.range = +PokitPro::CurrentRange::AutoRange;
      72             :         quint32 samplingWindow;  ///< Desired sampling window in microseconds.
      73             :         quint16 numberOfSamples; ///< Desired number of samples to acquire.
      74             :     };
      75             : 
      76             :     /// Values supported by the `Status` attribute of the `Metadata` characteristic.
      77             :     enum class DsoStatus : quint8 {
      78             :         Done       = 0,  ///< Sampling has completed.
      79             :         Sampling   = 1,  ///< Actively sampling.
      80             :         Error      = 255 ///< An error has occurred.
      81             :     };
      82             : 
      83             :     /// Attributes included in the `Metadata` characterstic.
      84             :     struct Metadata {
      85             :         DsoStatus status;        ///< Current DSO status.
      86             :         float scale;             ///< Scale to apply to read samples.
      87             :         Mode mode;               ///< Operation mode used during last acquisition.
      88             :         quint8 range;            ///< Range used during last acquisition.
      89             :         quint32 samplingWindow;  ///< Sampling window (microseconds) used during last acquisition.
      90             :         quint16 numberOfSamples; ///< Number of samples acquired (1 to 8192).
      91             :         quint32 samplingRate;    ///< Sampling rate  used during last acquisition (1 to 1MHz).
      92             :     };
      93             : 
      94             :     typedef QVector<qint16> Samples;
      95             : 
      96             :     DsoService(QLowEnergyController * const pokitDevice, QObject * parent = nullptr);
      97             :     ~DsoService() override;
      98             : 
      99             :     bool readCharacteristics() override;
     100             :     bool readMetadataCharacteristic();
     101             : 
     102             :     // Settings characteristic (BLE write only).
     103             :     bool setSettings(const Settings &settings);
     104             :     bool startDso(const Settings &settings);
     105             :     bool fetchSamples();
     106             : 
     107             :     // Metadata characteristic (BLE read/notify).
     108             :     Metadata metadata() const;
     109             :     bool enableMetadataNotifications();
     110             :     bool disableMetadataNotifications();
     111             : 
     112             :     // Reading characteristic (BLE notify only).
     113             :     bool enableReadingNotifications();
     114             :     bool disableReadingNotifications();
     115             : 
     116             : signals:
     117             :     void settingsWritten();
     118             :     void metadataRead(const DsoService::Metadata &meta);
     119             :     void samplesRead(const DsoService::Samples &samples);
     120             : 
     121             : protected:
     122             :     /// \cond internal
     123             :     DsoService(DsoServicePrivate * const d, QObject * const parent);
     124             :     /// \endcond
     125             : 
     126             : private:
     127         285 :     Q_DECLARE_PRIVATE(DsoService)
     128             :     Q_DISABLE_COPY(DsoService)
     129             :     friend class TestDsoService;
     130             : };
     131             : 
     132             : QTPOKIT_END_NAMESPACE
     133             : 
     134             : #endif // QTPOKIT_DSOSERVICE_H

Generated by: LCOV version 1.14