LCOV - code coverage report
Current view: top level - include/qtpokit - dsoservice.h (source / functions) Coverage Total Hit
Project: Dokit Lines: 4.1 % 74 3
Version: Functions: 100.0 % 2 2

            Line data    Source code
       1              : // SPDX-FileCopyrightText: 2022-2025 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         7995 :     Q_OBJECT
      26            0 : 
      27            0 : public:
      28            0 :     /// UUID of the "DSO" service.
      29            0 :     static inline const QBluetoothUuid serviceUuid { QStringLiteral("1569801e-1425-4a7a-b617-a4f4ed719de6") };
      30            0 : 
      31            0 :     /// Characteristics available via the `DSO` service.
      32            0 :     struct QTPOKIT_EXPORT CharacteristicUuids {
      33            0 :         /// UUID of the `DSO` service's `Settings` characteristic.
      34            0 :         static inline const QBluetoothUuid settings { QStringLiteral("a81af1b6-b8b3-4244-8859-3da368d2be39") };
      35            0 : 
      36            0 :         /// UUID of the `DSO` service's `Metadata` characteristic.
      37            0 :         static inline const QBluetoothUuid metadata { QStringLiteral("970f00ba-f46f-4825-96a8-153a5cd0cda9") };
      38            0 : 
      39            0 :         /// UUID of the `DSO` service's `Reading` characteristic.
      40            0 :         static inline const QBluetoothUuid reading  { QStringLiteral("98e14f8e-536e-4f24-b4f4-1debfed0a99e") };
      41            0 :     };
      42            0 : 
      43            0 :     /// Values supported by the `Command` attribute of the `Settings` characteristic.
      44            0 :     enum class Command : quint8 {
      45            0 :         FreeRunning        = 0, ///< Run free, without waiting for edge triggers.
      46            0 :         RisingEdgeTrigger  = 1, ///< Trigger on a rising edge.
      47            0 :         FallingEdgeTrigger = 2, ///< Trigger on a falling edge.
      48            0 :         ResendData         = 3  ///< Resend the last acquired data.
      49            0 :     };
      50            0 : 
      51            0 :     /// Values supported by the `Mode` attribute of the `Settings` and `Metadata` characteristics.
      52            0 :     enum class Mode : quint8 {
      53            0 :         Idle        = 0, ///< Make device idle.
      54            0 :         DcVoltage   = 1, ///< Measure DC voltage.
      55            0 :         AcVoltage   = 2, ///< Measure AC voltage.
      56            0 :         DcCurrent   = 3, ///< Measure DC current.
      57            0 :         AcCurrent   = 4, ///< Measure AC current.
      58            0 :     };
      59            0 :     static QString toString(const Mode &mode);
      60            0 : 
      61            0 :     static QString toString(const PokitProduct product, const quint8 range, const Mode mode);
      62            0 :     QString toString(const quint8 range, const Mode mode) const;
      63            0 :     static quint32 maxValue(const PokitProduct product, const quint8 range, const Mode mode);
      64            0 :     quint32 maxValue(const quint8 range, const Mode mode) const;
      65            0 : 
      66            0 :     /// Attributes included in the `Settings` characteristic.
      67            0 :     struct Settings {
      68            0 :         Command command;         ///< Custom operation request.
      69            0 :         float triggerLevel;      ///< Trigger threshold level in Volts or Amps, depending on #mode.
      70            0 :         Mode mode;               ///< Desired operation mode.
      71            0 :         quint8 range;            ///< Desired range, eg settings.range = +PokitPro::CurrentRange::AutoRange;
      72            0 :         quint32 samplingWindow;  ///< Desired sampling window in microseconds.
      73            0 :         quint16 numberOfSamples; ///< Desired number of samples to acquire.
      74            0 :     };
      75            0 : 
      76            0 :     /// Values supported by the `Status` attribute of the `Metadata` characteristic.
      77            0 :     enum class DsoStatus : quint8 {
      78            0 :         Done       = 0,  ///< Sampling has completed.
      79            0 :         Sampling   = 1,  ///< Actively sampling.
      80            0 :         Error      = 255 ///< An error has occurred.
      81            0 :     };
      82            0 : 
      83            0 :     /// Attributes included in the `Metadata` characteristic.
      84            0 :     struct Metadata {
      85            0 :         DsoStatus status;        ///< Current DSO status.
      86            0 :         float scale;             ///< Scale to apply to read samples.
      87            0 :         Mode mode;               ///< Operation mode used during last acquisition.
      88            0 :         quint8 range;            ///< Range used during last acquisition.
      89            0 :         quint32 samplingWindow;  ///< Sampling window (microseconds) used during last acquisition.
      90            0 :         quint16 numberOfSamples; ///< Number of samples acquired (1 to 8192).
      91            0 :         quint32 samplingRate;    ///< Sampling rate  used during last acquisition (1 to 1MHz).
      92            0 :     };
      93            0 : 
      94            0 :     typedef QVector<qint16> Samples;
      95            0 : 
      96            0 :     DsoService(QLowEnergyController * const pokitDevice, QObject * parent = nullptr);
      97         2712 :     ~DsoService() = default;
      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              : Q_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          975 :     Q_DECLARE_PRIVATE(DsoService)
     128              :     Q_DISABLE_COPY(DsoService)
     129              :     QTPOKIT_BEFRIEND_TEST(DsoService)
     130              : };
     131              : 
     132              : QTPOKIT_END_NAMESPACE
     133              : 
     134              : #endif // QTPOKIT_DSOSERVICE_H
        

Generated by: LCOV version 2.3.2-1