summaryrefslogtreecommitdiffstats
path: root/src/bluetooth/qlowenergyconnectionparameters.cpp
diff options
context:
space:
mode:
authorChristian Kandeler <christian.kandeler@theqtcompany.com>2016-01-12 12:22:11 +0100
committerAlex Blasche <alexander.blasche@theqtcompany.com>2016-01-18 07:46:35 +0000
commite94fe90e7d2e1df9bd7d1d014fb468e5e73da834 (patch)
tree440a4e0359661b6cc4ac2e95455475ff0d64ebcd /src/bluetooth/qlowenergyconnectionparameters.cpp
parent1046db1a91f264db6714975daa27f56a457a6778 (diff)
Bluetooth LE: Add connection update functionality.
Implemented for BlueZ only. Change-Id: I358a98bbc7499d5ce5437fb0d4672fde46c3b831 Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com>
Diffstat (limited to 'src/bluetooth/qlowenergyconnectionparameters.cpp')
-rw-r--r--src/bluetooth/qlowenergyconnectionparameters.cpp202
1 files changed, 202 insertions, 0 deletions
diff --git a/src/bluetooth/qlowenergyconnectionparameters.cpp b/src/bluetooth/qlowenergyconnectionparameters.cpp
new file mode 100644
index 00000000..727ed141
--- /dev/null
+++ b/src/bluetooth/qlowenergyconnectionparameters.cpp
@@ -0,0 +1,202 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the QtBluetooth module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL21$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 or version 3 as published by the Free
+** Software Foundation and appearing in the file LICENSE.LGPLv21 and
+** LICENSE.LGPLv3 included in the packaging of this file. Please review the
+** following information to ensure the GNU Lesser General Public License
+** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** As a special exception, The Qt Company gives you certain additional
+** rights. These rights are described in The Qt Company LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qlowenergyconnectionparameters.h"
+
+QT_BEGIN_NAMESPACE
+
+class QLowEnergyConnectionParametersPrivate : public QSharedData
+{
+public:
+ QLowEnergyConnectionParametersPrivate()
+ : minInterval(7.5)
+ , maxInterval(4000)
+ , latency(0)
+ , timeout(32000)
+ {
+ }
+
+ double minInterval;
+ double maxInterval;
+ int latency;
+ int timeout;
+};
+
+/*!
+ \since 5.7
+ \class QLowEnergyConnectionParameters
+ \brief The QLowEnergyConnectionParameters class is used when requesting or reporting
+ an update of the parameters of a Bluetooth LE connection.
+
+ The connection parameters influence how often a master and a slave device synchronize
+ with each other. In general, a lower connection interval and latency means faster communication,
+ but also higher power consumption. How these criteria should be weighed against each other
+ is highly dependent on the concrete use case.
+ \inmodule QtBluetooth
+ \ingroup shared
+
+ \sa QLowEnergyController::requestConnectionUpdate
+ \sa QLowEnergyController::connectionUpdated
+*/
+
+
+/*!
+ Constructs a new object of this class. All values are initialized to valid defaults.
+ */
+QLowEnergyConnectionParameters::QLowEnergyConnectionParameters()
+ : d(new QLowEnergyConnectionParametersPrivate)
+{
+}
+
+/*! Constructs a new object of this class that is a copy of \a other. */
+QLowEnergyConnectionParameters::QLowEnergyConnectionParameters(const QLowEnergyConnectionParameters &other)
+ : d(other.d)
+{
+}
+
+/*! Destroys this object. */
+QLowEnergyConnectionParameters::~QLowEnergyConnectionParameters()
+{
+}
+
+/*! Makes this object a copy of \a other and returns the new value of this object. */
+QLowEnergyConnectionParameters &QLowEnergyConnectionParameters::operator=(const QLowEnergyConnectionParameters &other)
+{
+ d = other.d;
+ return *this;
+}
+
+/*!
+ Sets the range in which the connection interval should be. The actual value will be decided by
+ the controller. Both \a minimum and \a maximum are given in milliseconds.
+ If \a maximum is smaller than \a minimum, it will be set to the value of \a minimum.
+ The smallest possible connection interval is 7.5 milliseconds, the largest one is
+ 4000 milliseconds.
+ \sa minimumInterval(), maximumInterval()
+ */
+void QLowEnergyConnectionParameters::setIntervalRange(double minimum, double maximum)
+{
+ d->minInterval = minimum;
+ d->maxInterval = qMax(minimum, maximum);
+}
+
+/*!
+ Returns the minimum connection interval in milliseconds. The default is 7.5.
+ \note If this object was emitted via \l QLowEnergyController::connectionUpdated(), then
+ this value is the same as \l maximumInterval() and refers to the actual
+ connection interval.
+ \sa setIntervalRange()
+ */
+double QLowEnergyConnectionParameters::minimumInterval() const
+{
+ return d->minInterval;
+}
+
+/*!
+ Returns the maximum connection interval in milliseconds. The default is 4000.
+ \note If this object was emitted via \l QLowEnergyController::connectionUpdated(), then
+ this value is the same as \l minimumInterval() and refers to the actual
+ connection interval.
+ \sa setIntervalRange()
+ */
+double QLowEnergyConnectionParameters::maximumInterval() const
+{
+ return d->maxInterval;
+}
+
+/*!
+ Sets the slave latency of the connection (that is, the number of connection events that a slave
+ device is allowed to ignore) to \a latency. The minimum value is 0, the maximum is 499.
+ \sa latency()
+ */
+void QLowEnergyConnectionParameters::setLatency(int latency)
+{
+ d->latency = latency;
+}
+
+/*!
+ Returns the slave latency of the connection.
+ \sa setLatency()
+*/
+int QLowEnergyConnectionParameters::latency() const
+{
+ return d->latency;
+}
+
+/*!
+ Sets the link supervision timeout to \a timeout milliseconds.
+ There are several constraints on this value: It must be in the range [100,32000] and it must be
+ larger than (1 + \l latency()) * 2 * \l maximumInterval().
+ \sa supervisionTimeout()
+ */
+void QLowEnergyConnectionParameters::setSupervisionTimeout(int timeout)
+{
+ d->timeout = timeout;
+}
+
+/*!
+ Returns the link supervision timeout of the connection in milliseconds.
+ \sa setSupervisionTimeout()
+*/
+int QLowEnergyConnectionParameters::supervisionTimeout() const
+{
+ return d->timeout;
+}
+
+/*!
+ \fn void QLowEnergyConnectionParameters::swap(QLowEnergyConnectionParameters &other)
+ Swaps this object with \a other.
+ */
+
+/*!
+ Returns \a true if \a p1 and \a p2 are equal with respect to their public state,
+ otherwise returns false.
+ */
+bool operator==(const QLowEnergyConnectionParameters &p1, const QLowEnergyConnectionParameters &p2)
+{
+ if (p1.d == p2.d)
+ return true;
+ return p1.minimumInterval() == p2.minimumInterval()
+ && p1.maximumInterval() == p2.maximumInterval()
+ && p1.latency() == p2.latency()
+ && p1.supervisionTimeout() == p2.supervisionTimeout();
+}
+
+/*!
+ \fn bool operator!=(const QLowEnergyConnectionParameters &p1,
+ const QLowEnergyConnectionParameters &p2)
+ Returns \a true if \a p1 and \a p2 are not equal with respect to their public state,
+ otherwise returns false.
+ */
+
+QT_END_NAMESPACE