summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2018-09-24 17:39:33 -0700
committerGravatar Dirk Hohndel <dirk@hohndel.org>2018-10-12 08:22:44 -0700
commit0cfd76740b1af1424c39151e1628e1af6480a2d6 (patch)
tree6665240dc11add7f4856ec3106b424a7e7183b2e
parent4263d1c3f57bd8080f821c564018d0a6f0b5cb3c (diff)
downloadsubsurface-0cfd76740b1af1424c39151e1628e1af6480a2d6.tar.gz
core: helper function to recognize BT/BLE addresses
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r--core/btdiscovery.cpp9
-rw-r--r--core/btdiscovery.h1
2 files changed, 10 insertions, 0 deletions
diff --git a/core/btdiscovery.cpp b/core/btdiscovery.cpp
index a37f36a92..1527be624 100644
--- a/core/btdiscovery.cpp
+++ b/core/btdiscovery.cpp
@@ -6,6 +6,7 @@
#include <QTimer>
#include <QDebug>
#include <QLoggingCategory>
+#include <QRegularExpression>
extern QMap<QString, dc_descriptor_t *> descriptorLookup;
@@ -301,6 +302,14 @@ bool BTDiscovery::checkException(const char* method, const QAndroidJniObject *ob
QHash<QString, QBluetoothDeviceInfo> btDeviceInfo;
+bool isBluetoothAddress(const QString &address)
+{
+ QRegularExpression re("(LE:)*([0-9A-F]{2}:[0-9A-F]{2}:[0-9A-F]{2}:[0-9A-F]{2}:[0-9A-F]{2}:[0-9A-F]{2}|{[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}})",
+ QRegularExpression::CaseInsensitiveOption);
+ QRegularExpressionMatch m = re.match(address);
+ return m.hasMatch();
+}
+
void saveBtDeviceInfo(const QString &devaddr, QBluetoothDeviceInfo deviceInfo)
{
btDeviceInfo[devaddr] = deviceInfo;
diff --git a/core/btdiscovery.h b/core/btdiscovery.h
index 212585688..beabdf122 100644
--- a/core/btdiscovery.h
+++ b/core/btdiscovery.h
@@ -17,6 +17,7 @@
#endif
void saveBtDeviceInfo(const QString &devaddr, QBluetoothDeviceInfo deviceInfo);
+bool isBluetoothAddress(const QString &address);
QBluetoothDeviceInfo getBtDeviceInfo(const QString &devaddr);
class BTDiscovery : public QObject {