Dokit
Internal development documentation
Loading...
Searching...
No Matches
devicecommand.h
1// SPDX-FileCopyrightText: 2022-2023 Paul Colby <git@colby.id.au>
2// SPDX-License-Identifier: LGPL-3.0-or-later
3
4#ifndef DOKIT_DEVICECOMMAND_H
5#define DOKIT_DEVICECOMMAND_H
6
7#include "abstractcommand.h"
9
10#include <QLowEnergyController>
11
13class PokitDevice;
14
16{
18
19public:
20 explicit DeviceCommand(QObject * const parent = nullptr);
21
22public slots:
23 bool start() override;
24
25protected:
26 PokitDevice * device { nullptr }; ///< Pokit Bluetooth device (if any) this command inerracts with.
27 int exitCodeOnDisconnect { EXIT_FAILURE }; ///< Exit code to return on device disconnection.
28
29 void disconnect(int exitCode=EXIT_SUCCESS);
31
32 template<typename T> static T minRange(const quint32 maxValue);
33 static quint8 minCapacitanceRange(const PokitProduct product, const quint32 maxValue);
34 static quint8 minCurrentRange(const PokitProduct product, const quint32 maxValue);
35 static quint8 minResistanceRange(const PokitProduct product, const quint32 maxValue);
36 static quint8 minVoltageRange(const PokitProduct product, const quint32 maxValue);
37
38protected slots:
39 virtual void controllerError(const QLowEnergyController::Error error);
40 virtual void deviceDisconnected();
41 virtual void serviceError(const QLowEnergyService::ServiceError error);
42 virtual void serviceDetailsDiscovered();
43
44private slots:
45 // These are protected in the base class, but hidden (private) for our descendents.
46 void deviceDiscovered(const QBluetoothDeviceInfo &info) override;
47 void deviceDiscoveryFinished() override;
48
49 friend class TestDeviceCommand;
50};
51
52#endif // DOKIT_DEVICECOMMAND_H
The AbstractCommand class provides a consistent base for the classes that implement CLI commands.
The AbstractPokitService class provides a common base for Pokit services classes.
The AbstractCommand class extends AbstractCommand to add a PokitDevice instance.
static quint8 minResistanceRange(const PokitProduct product, const quint32 maxValue)
Returns the product's lowest resistance range that can measure at least up to maxValue (Ω),...
virtual void controllerError(const QLowEnergyController::Error error)
Handles controller error events.
PokitDevice * device
Pokit Bluetooth device (if any) this command inerracts with.
static T minRange(const quint32 maxValue)
virtual void deviceDisconnected()
Handles devics disconnection events.
DeviceCommand(QObject *const parent=nullptr)
Construct a new DeviceCommand object with parent.
bool start() override
Begins scanning for the Pokit device.
int exitCodeOnDisconnect
Exit code to return on device disconnection.
void deviceDiscoveryFinished() override
Checks that the requested device was discovered, and if not, reports and error and exits.
static quint8 minCapacitanceRange(const PokitProduct product, const quint32 maxValue)
Returns the product's lowest capacitance range that can measure at least up to maxValue (nF),...
virtual AbstractPokitService * getService()=0
Returns a Pokit service object for the derived command class.
virtual void serviceDetailsDiscovered()
Handles service detail discovery events.
static quint8 minVoltageRange(const PokitProduct product, const quint32 maxValue)
t Returns the product's lowest voltage range that can measure at least up to maxValue (mV),...
virtual void serviceError(const QLowEnergyService::ServiceError error)
Handles service error events.
static quint8 minCurrentRange(const PokitProduct product, const quint32 maxValue)
Returns the product's lowest current range that can measure at least up to maxValue (µA),...
void deviceDiscovered(const QBluetoothDeviceInfo &info) override
Checks if info is the device (if any) we're looking for, and if so, create a contoller and service,...
void disconnect(int exitCode=EXIT_SUCCESS)
Disconnects the underlying Pokit device, and sets exitCode to be return to the OS once the disconnect...
The PokitDevice class simplifies Pokit device access.
Definition pokitdevice.h:32
Declares the PokitProduct enumeration, and related helper functions.
PokitProduct
Pokit products known to, and supported by, the QtPokit library.
Q_OBJECTQ_OBJECT
QObject * parent() const const