LCOV - code coverage report
Current view: top level - include/qtpokit - dataloggerservice.h (source / functions) Coverage Total Hit
Project: Dokit Lines: 4.0 % 75 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 DataLoggerService class.
       7              :  */
       8              : 
       9              : #ifndef QTPOKIT_DATALOGGERSERVICE_H
      10              : #define QTPOKIT_DATALOGGERSERVICE_H
      11              : 
      12              : #include "abstractpokitservice.h"
      13              : 
      14              : #include <QBluetoothAddress>
      15              : #include <QBluetoothUuid>
      16              : #include <QVersionNumber>
      17              : 
      18              : QTPOKIT_BEGIN_NAMESPACE
      19              : 
      20              : class DataLoggerServicePrivate;
      21              : 
      22              : class QTPOKIT_EXPORT DataLoggerService : public AbstractPokitService
      23              : {
      24        10010 :     Q_OBJECT
      25            0 : 
      26            0 : public:
      27            0 :     /// UUID of the "DataLogger" service.
      28            0 :     static inline const QBluetoothUuid serviceUuid { QStringLiteral("a5ff3566-1fd8-4e10-8362-590a578a4121") };
      29            0 : 
      30            0 :     /// Characteristics available via the `DataLogger` service.
      31            0 :     struct QTPOKIT_EXPORT CharacteristicUuids {
      32            0 :         /// UUID of the `DataLogger` service's `Settings` characteristic.
      33            0 :         static inline const QBluetoothUuid settings { QStringLiteral("5f97c62b-a83b-46c6-b9cd-cac59e130a78") };
      34            0 : 
      35            0 :         /// UUID of the `DataLogger` service's `Metadata` characteristic.
      36            0 :         static inline const QBluetoothUuid metadata { QStringLiteral("9acada2e-3936-430b-a8f7-da407d97ca6e") };
      37            0 : 
      38            0 :         /// UUID of the `DataLogger` service's `Reading` characteristic.
      39            0 :         static inline const QBluetoothUuid reading  { QStringLiteral("3c669dab-fc86-411c-9498-4f9415049cc0") };
      40            0 :     };
      41            0 : 
      42            0 :     /// Values supported by the `Command` attribute of the `Settings` characteristic.
      43            0 :     enum class Command : quint8 {
      44            0 :         Start   = 0, ///< Start the Data Logger.
      45            0 :         Stop    = 1, ///< Stop the Data Logger.
      46            0 :         Refresh = 2, ///< Refresh the Data Logger.
      47            0 :     };
      48            0 : 
      49            0 :     /// Values supported by the `Mode` attribute of the `Settings` and `Metadata` characteristics.
      50            0 :     enum class Mode : quint8 {
      51            0 :         Idle        = 0, ///< Make device idle.
      52            0 :         DcVoltage   = 1, ///< Measure DC voltage.
      53            0 :         AcVoltage   = 2, ///< Measure AC voltage.
      54            0 :         DcCurrent   = 3, ///< Measure DC current.
      55            0 :         AcCurrent   = 4, ///< Measure AC current.
      56            0 :         Temperature = 5, ///< Measure temperature.
      57            0 :     };
      58            0 :     static QString toString(const Mode &mode);
      59            0 : 
      60            0 :     static QString toString(const PokitProduct product, const quint8 range, const Mode mode);
      61            0 :     QString toString(const quint8 range, const Mode mode) const;
      62            0 :     static quint32 maxValue(const PokitProduct product, const quint8 range, const Mode mode);
      63            0 :     quint32 maxValue(const quint8 range, const Mode mode) const;
      64            0 : 
      65            0 :     /// Attributes included in the `Settings` characteristic.
      66            0 :     struct Settings {
      67            0 :         Command command;        ///< Custom operation request.
      68            0 :         quint16 arguments;      ///< Reserved to used along with #command in future.
      69            0 :         Mode mode;              ///< Desired operation mode.
      70            0 :         quint8 range;           ///< Desired range.
      71            0 :         quint32 updateInterval; ///< Desired update interval in milliseconds.
      72            0 :         quint32 timestamp;      ///< Custom timestamp for start time in retrieved metadata.
      73            0 :     };
      74            0 : 
      75            0 :     /// Values supported by the `Status` attribute of the `Metadata` characteristic.
      76            0 :     enum class LoggerStatus : quint8 {
      77            0 :         Done       = 0,   ///< Sampling has completed.
      78            0 :         Sampling   = 1,   ///< Actively sampling.
      79            0 :         BufferFull = 2,   ///< Buffer is full.
      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 :         LoggerStatus status;     ///< Current data logger status.
      86            0 :         float scale;             ///< Scale to apply to read samples.
      87            0 :         Mode mode;               ///< Current operation mode.
      88            0 :         quint8 range;            ///< Current range.
      89            0 :         quint32 updateInterval;  ///< Current logging interval in milliseconds.
      90            0 :         quint16 numberOfSamples; ///< Number of samples acquired (1 to 6192).
      91            0 :         quint32 timestamp;       ///< Timestamp stored at the beginning of the logging session.
      92            0 :     };
      93            0 : 
      94            0 :     typedef QVector<qint16> Samples;
      95            0 : 
      96            0 :     DataLoggerService(QLowEnergyController * const pokitDevice, QObject * parent = nullptr);
      97         3051 :     ~DataLoggerService() = default;
      98              : 
      99              :     bool readCharacteristics() override;
     100              :     bool readMetadataCharacteristic();
     101              : 
     102              :     // Settings characteristic (BLE write only).
     103              :     bool setSettings(const Settings &settings);
     104              :     bool startLogger(const Settings &settings);
     105              :     bool stopLogger();
     106              :     bool fetchSamples();
     107              : 
     108              :     // Metadata characteristic (BLE read/notify).
     109              :     Metadata metadata() const;
     110              :     bool enableMetadataNotifications();
     111              :     bool disableMetadataNotifications();
     112              : 
     113              :     // Reading characteristic (BLE notify only).
     114              :     bool enableReadingNotifications();
     115              :     bool disableReadingNotifications();
     116              : 
     117              : Q_SIGNALS:
     118              :     void settingsWritten();
     119              :     void metadataRead(const DataLoggerService::Metadata &meta);
     120              :     void samplesRead(const DataLoggerService::Samples &samples);
     121              : 
     122              : protected:
     123              :     /// \cond internal
     124              :     DataLoggerService(DataLoggerServicePrivate * const d, QObject * const parent);
     125              :     /// \endcond
     126              : 
     127              : private:
     128          910 :     Q_DECLARE_PRIVATE(DataLoggerService)
     129              :     Q_DISABLE_COPY(DataLoggerService)
     130              :     QTPOKIT_BEFRIEND_TEST(DataLoggerService)
     131              : };
     132              : 
     133              : QTPOKIT_END_NAMESPACE
     134              : 
     135              : #endif // QTPOKIT_DATALOGGERSERVICE_H
        

Generated by: LCOV version 2.3.2-1