LCOV - code coverage report
Current view: top level - include/qtpokit - dataloggerservice.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 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        3655 :     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             :         Start   = 0, ///< Start the Data Logger.
      37             :         Stop    = 1, ///< Stop the Data Logger.
      38             :         Refresh = 2, ///< Refresh the Data Logger.
      39             :     };
      40             : 
      41             :     enum class Mode : quint8 {
      42             :         Idle        = 0, ///< Make device idle.
      43             :         DcVoltage   = 1, ///< Measure DC voltage.
      44             :         AcVoltage   = 2, ///< Measure AC voltage.
      45             :         DcCurrent   = 3, ///< Measure DC current.
      46             :         AcCurrent   = 4, ///< Measure AC current.
      47             :         /// \todo Pokit Pro supports temperature in logger mode too.
      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, which are enum 6 and 7 via Android app.
      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             :         quint16 arguments;      ///< Reserved to used along with #command in future.
      88             :         Mode mode;              ///< Desired operation mode.
      89             :         Range range;            ///< Desired range.
      90             :         quint32 updateInterval; ///< Desired update interval in milliseconds.
      91             :         quint32 timestamp;      ///< Custom timestamp for start time in retrieved metadata.
      92             :     };
      93             : 
      94             :     enum class LoggerStatus : quint8 {
      95             :         Done       = 0,   ///< Sampling has completed.
      96             :         Sampling   = 1,   ///< Actively sampling.
      97             :         BufferFull = 2,   ///< Buffer is full.
      98             :         Error      = 255  ///< An error has occurred.
      99             :     };
     100             : 
     101        1054 :     struct Metadata {
     102             :         LoggerStatus status;     ///< Current data logger status.
     103             :         float scale;             ///< Scale to apply to read samples.
     104             :         Mode mode;               ///< Current operation mode.
     105             :         Range range;             ///< Current range.
     106             :         quint32 updateInterval;  ///< Current logging interval in milliseconds.
     107             :         quint16 numberOfSamples; ///< Number of samples acquired (1 to 6192).
     108             :         quint32 timestamp;       ///< Timestamp stored at the beginning of the logging session.
     109             :     };
     110             : 
     111             :     typedef QVector<qint16> Samples;
     112             : 
     113             :     DataLoggerService(QLowEnergyController * const pokitDevice, QObject * parent = nullptr);
     114             :     ~DataLoggerService() override;
     115             : 
     116             :     bool readCharacteristics() override;
     117             :     bool readMetadataCharacteristic();
     118             : 
     119             :     // Settings characteristic (BLE write only).
     120             :     bool setSettings(const Settings &settings);
     121             :     bool startLogger(const Settings &settings);
     122             :     bool stopLogger();
     123             :     bool fetchSamples();
     124             : 
     125             :     // Metadata characteristic (BLE read/notify).
     126             :     Metadata metadata() const;
     127             :     bool enableMetadataNotifications();
     128             :     bool disableMetadataNotifications();
     129             : 
     130             :     // Reading characteristic (BLE notify only).
     131             :     bool enableReadingNotifications();
     132             :     bool disableReadingNotifications();
     133             : 
     134             : signals:
     135             :     void settingsWritten();
     136             :     void metadataRead(const DataLoggerService::Metadata &meta);
     137             :     void samplesRead(const DataLoggerService::Samples &samples);
     138             : 
     139             : protected:
     140             :     /// \cond internal
     141             :     DataLoggerService(DataLoggerServicePrivate * const d, QObject * const parent);
     142             :     /// \endcond
     143             : 
     144             : private:
     145         238 :     Q_DECLARE_PRIVATE(DataLoggerService)
     146             :     Q_DISABLE_COPY(DataLoggerService)
     147             :     friend class TestDataLoggerService;
     148             : };
     149             : 
     150             : QTPOKIT_EXPORT bool operator==(const DataLoggerService::Range &lhs, const DataLoggerService::Range &rhs);
     151             : QTPOKIT_EXPORT bool operator!=(const DataLoggerService::Range &lhs, const DataLoggerService::Range &rhs);
     152             : QTPOKIT_EXPORT bool operator< (const DataLoggerService::Range &lhs, const DataLoggerService::Range &rhs);
     153             : QTPOKIT_EXPORT bool operator> (const DataLoggerService::Range &lhs, const DataLoggerService::Range &rhs);
     154             : QTPOKIT_EXPORT bool operator<=(const DataLoggerService::Range &lhs, const DataLoggerService::Range &rhs);
     155             : QTPOKIT_EXPORT bool operator>=(const DataLoggerService::Range &lhs, const DataLoggerService::Range &rhs);
     156             : 
     157             : QTPOKIT_END_NAMESPACE
     158             : 
     159             : #endif // QTPOKIT_DATALOGGERSERVICE_H

Generated by: LCOV version 1.14