diff options
| author | Andrew Branson <abranson@users.noreply.github.com> | 2015-06-10 00:31:11 +0200 |
|---|---|---|
| committer | Andrew Branson <abranson@users.noreply.github.com> | 2015-06-10 00:31:11 +0200 |
| commit | 9f19addbe51a1ceb2967b737843dab0e262343c0 (patch) | |
| tree | 0f3d3d30289256f9485774822d354bb5d5f50f3b /daemon | |
| parent | 2d50346f06e5be31557cb4718ff94cd650c1a210 (diff) | |
| parent | 882b7b9327edb3dd73fa3e82eba83c0405f91b83 (diff) | |
Merge pull request #1 from smokku/master
Pull
Diffstat (limited to 'daemon')
| -rw-r--r-- | daemon/daemon.pro | 2 | ||||
| -rw-r--r-- | daemon/dbusconnector.cpp | 77 | ||||
| -rw-r--r-- | daemon/dbusconnector.h | 31 | ||||
| -rw-r--r-- | daemon/manager.cpp | 25 | ||||
| -rw-r--r-- | daemon/manager.h | 17 | ||||
| -rw-r--r-- | daemon/musicmanager.cpp | 4 | ||||
| -rw-r--r-- | daemon/notificationmanager.cpp | 21 | ||||
| -rw-r--r-- | daemon/settings.h | 19 | ||||
| -rw-r--r-- | daemon/watchconnector.cpp | 152 | ||||
| -rw-r--r-- | daemon/watchconnector.h | 43 |
10 files changed, 168 insertions, 223 deletions
diff --git a/daemon/daemon.pro b/daemon/daemon.pro index 40d3290..4520b57 100644 --- a/daemon/daemon.pro +++ b/daemon/daemon.pro @@ -16,7 +16,6 @@ SOURCES += \ voicecallhandler.cpp \ notificationmanager.cpp \ watchconnector.cpp \ - dbusconnector.cpp \ appmanager.cpp \ musicmanager.cpp \ datalogmanager.cpp \ @@ -36,7 +35,6 @@ HEADERS += \ voicecallhandler.h \ notificationmanager.h \ watchconnector.h \ - dbusconnector.h \ settings.h \ appmanager.h \ musicmanager.h \ diff --git a/daemon/dbusconnector.cpp b/daemon/dbusconnector.cpp deleted file mode 100644 index ccc127d..0000000 --- a/daemon/dbusconnector.cpp +++ /dev/null @@ -1,77 +0,0 @@ -#include "dbusconnector.h" - -#include <QBluetoothAddress> -#include <QBluetoothLocalDevice> -#include <QDebug> -#include <QDBusConnection> -#include <QDBusMessage> -#include <QDBusReply> -#include <QDBusArgument> -#include <QDBusObjectPath> - -//dbus-send --system --dest=org.bluez --print-reply / org.bluez.Manager.ListAdapters -//dbus-send --system --dest=org.bluez --print-reply $path org.bluez.Adapter.GetProperties -//dbus-send --system --dest=org.bluez --print-reply $devpath org.bluez.Device.GetProperties -//dbus-send --system --dest=org.bluez --print-reply $devpath org.bluez.Input.Connect - -DBusConnector::DBusConnector(QObject *parent) : - QObject(parent), l(metaObject()->className()) -{} - -bool DBusConnector::findPebble() -{ - QDBusConnection system = QDBusConnection::systemBus(); - - QDBusReply<QList<QDBusObjectPath>> ListAdaptersReply = system.call( - QDBusMessage::createMethodCall("org.bluez", "/", "org.bluez.Manager", - "ListAdapters")); - if (not ListAdaptersReply.isValid()) { - qCCritical(l) << ListAdaptersReply.error().message(); - return false; - } - - QList<QDBusObjectPath> adapters = ListAdaptersReply.value(); - - if (adapters.isEmpty()) { - qCDebug(l) << "No BT adapters found"; - return false; - } - - QDBusReply<QVariantMap> AdapterPropertiesReply = system.call( - QDBusMessage::createMethodCall("org.bluez", adapters[0].path(), "org.bluez.Adapter", - "GetProperties")); - if (not AdapterPropertiesReply.isValid()) { - qCCritical(l) << AdapterPropertiesReply.error().message(); - return false; - } - - QList<QDBusObjectPath> devices; - AdapterPropertiesReply.value()["Devices"].value<QDBusArgument>() >> devices; - - foreach (QDBusObjectPath path, devices) { - QDBusReply<QVariantMap> DevicePropertiesReply = system.call( - QDBusMessage::createMethodCall("org.bluez", path.path(), "org.bluez.Device", - "GetProperties")); - if (not DevicePropertiesReply.isValid()) { - qCCritical(l) << DevicePropertiesReply.error().message(); - continue; - } - - const QVariantMap &dict = DevicePropertiesReply.value(); - - QString tmp = dict["Name"].toString(); - qCDebug(l) << "Found BT device:" << tmp; - if (tmp.startsWith("Pebble")) { - qCDebug(l) << "Found Pebble:" << tmp; - QBluetoothAddress addr(dict["Address"].toString()); - QBluetoothLocalDevice dev; - if (dev.pairingStatus(addr) == QBluetoothLocalDevice::AuthorizedPaired) { - pebbleProps = dict; - emit pebbleChanged(); - return true; - } - } - } - - return false; -} diff --git a/daemon/dbusconnector.h b/daemon/dbusconnector.h deleted file mode 100644 index 6b48f99..0000000 --- a/daemon/dbusconnector.h +++ /dev/null @@ -1,31 +0,0 @@ -#ifndef DBUSCONNECTOR_H -#define DBUSCONNECTOR_H - -#include <QObject> -#include <QStringList> -#include <QVariantMap> -#include <QLoggingCategory> - -// TODO Remove this. - -class DBusConnector : public QObject -{ - Q_OBJECT - QLoggingCategory l; - - Q_PROPERTY(QVariantMap pebble READ pebble NOTIFY pebbleChanged) - QVariantMap pebbleProps; - -public: - explicit DBusConnector(QObject *parent = 0); - - QVariantMap pebble() const { return pebbleProps; } - -signals: - void pebbleChanged(); - -public slots: - bool findPebble(); -}; - -#endif // DBUSCONNECTOR_H diff --git a/daemon/manager.cpp b/daemon/manager.cpp index e6ebf26..179d05e 100644 --- a/daemon/manager.cpp +++ b/daemon/manager.cpp @@ -10,7 +10,6 @@ Manager::Manager(Settings *settings, QObject *parent) : QObject(parent), l(metaObject()->className()), settings(settings), proxy(new PebbledProxy(this)), watch(new WatchConnector(this)), - dbus(new DBusConnector(this)), upload(new UploadManager(watch, this)), apps(new AppManager(this)), bank(new BankManager(watch, upload, apps, this)), @@ -67,8 +66,8 @@ Manager::Manager(Settings *settings, QObject *parent) : session.registerObject("/org/pebbled/Watch", proxy); session.registerService("org.pebbled"); - connect(dbus, &DBusConnector::pebbleChanged, proxy, &PebbledProxy::NameChanged); - connect(dbus, &DBusConnector::pebbleChanged, proxy, &PebbledProxy::AddressChanged); + connect(watch, &WatchConnector::pebbleChanged, proxy, &PebbledProxy::NameChanged); + connect(watch, &WatchConnector::pebbleChanged, proxy, &PebbledProxy::AddressChanged); connect(watch, &WatchConnector::connectedChanged, proxy, &PebbledProxy::ConnectedChanged); connect(watch, &WatchConnector::versionsChanged, proxy, &PebbledProxy::InfoChanged); connect(bank, &BankManager::slotsChanged, proxy, &PebbledProxy::AppSlotsChanged); @@ -79,11 +78,7 @@ Manager::Manager(Settings *settings, QObject *parent) : // Set BT icon for notification notification.setImage("icon-system-bluetooth-device"); - if (btDevice.isValid()) { - qCDebug(l) << "BT local name:" << btDevice.name(); - connect(dbus, SIGNAL(pebbleChanged()), SLOT(onPebbleChanged())); - dbus->findPebble(); - } + watch->findPebbles(); } Manager::~Manager() @@ -100,17 +95,6 @@ void Manager::onSettingsChanged() qCWarning(l) << __FUNCTION__ << "Not implemented!"; } -void Manager::onPebbleChanged() -{ - const QVariantMap & pebble = dbus->pebble(); - QString name = pebble["Name"].toString(); - if (name.isEmpty()) { - qCDebug(l) << "Pebble gone"; - } else { - watch->deviceConnect(name, pebble["Address"].toString()); - } -} - void Manager::onConnectedChanged() { QString message = QString("%1 %2") @@ -130,8 +114,7 @@ void Manager::onActiveVoiceCallChanged() { qCDebug(l) << "Manager::onActiveVoiceCallChanged()"; - QVariant incomingCallNotification = settings->property("incomingCallNotification"); - if (incomingCallNotification.isValid() && !incomingCallNotification.toBool()) { + if (!settings->property("incomingCallNotification").toBool()) { qCDebug(l) << "Ignoring ActiveVoiceCallChanged because of setting!"; return; } diff --git a/daemon/manager.h b/daemon/manager.h index 2079de0..a605ed1 100644 --- a/daemon/manager.h +++ b/daemon/manager.h @@ -2,7 +2,6 @@ #define MANAGER_H #include "watchconnector.h" -#include "dbusconnector.h" #include "uploadmanager.h" #include "voicecallmanager.h" #include "notificationmanager.h" @@ -15,7 +14,6 @@ #include "settings.h" #include <QObject> -#include <QBluetoothLocalDevice> #include <QDBusContext> #include <QtContacts/QContactManager> #include <QtContacts/QContactDetailFilter> @@ -35,14 +33,11 @@ class Manager : public QObject, protected QDBusContext friend class PebbledProxy; - QBluetoothLocalDevice btDevice; - Settings *settings; PebbledProxy *proxy; WatchConnector *watch; - DBusConnector *dbus; UploadManager *upload; AppManager *apps; BankManager *bank; @@ -79,7 +74,6 @@ public slots: private slots: void onSettingChanged(const QString &key); void onSettingsChanged(); - void onPebbleChanged(); void onConnectedChanged(); void onActiveVoiceCallChanged(); void onVoiceError(const QString &message); @@ -113,16 +107,15 @@ class PebbledProxy : public QObject, protected QDBusContext Q_PROPERTY(QVariantList AllApps READ AllApps NOTIFY AllAppsChanged) inline Manager* manager() const { return static_cast<Manager*>(parent()); } - inline QVariantMap pebble() const { return manager()->dbus->pebble(); } public: inline explicit PebbledProxy(QObject *parent) : QObject(parent), l(metaObject()->className()) {} - inline QString Name() const { return pebble()["Name"].toString(); } - inline QString Address() const { return pebble()["Address"].toString(); } - inline QVariantMap Info() const { return manager()->watch->versions().toMap(); } - inline bool Connected() const { return manager()->watch->isConnected(); } + inline QString Name() const { qCDebug(l) << manager()->watch->name(); return manager()->watch->name(); } + inline QString Address() const { qCDebug(l) << manager()->watch->address().toString(); return manager()->watch->address().toString(); } + inline QVariantMap Info() const { qCDebug(l) << manager()->watch->versions().toMap(); return manager()->watch->versions().toMap(); } + inline bool Connected() const { qCDebug(l) << manager()->watch->isConnected(); return manager()->watch->isConnected(); } inline QString AppUuid() const { return manager()->currentAppUuid.toString(); } QStringList AppSlots() const; @@ -131,7 +124,7 @@ public: public slots: inline void Disconnect() { manager()->watch->disconnect(); } - inline void Reconnect() { manager()->watch->reconnect(); } + inline void Reconnect() { manager()->watch->connect(); } inline void Ping(uint val) { manager()->watch->ping(val); } inline void SyncTime() { manager()->watch->time(); } diff --git a/daemon/musicmanager.cpp b/daemon/musicmanager.cpp index 5ae1786..2a426db 100644 --- a/daemon/musicmanager.cpp +++ b/daemon/musicmanager.cpp @@ -148,11 +148,9 @@ void MusicManager::callMprisMethod(const QString &method) void MusicManager::handleMusicControl(WatchConnector::MusicControl operation) { qCDebug(l) << "operation from watch:" << operation; - QVariant useSystemVolumeVar = settings->property("useSystemVolume"); - bool useSystemVolume = (useSystemVolumeVar.isValid() && useSystemVolumeVar.toBool()); // System volume controls - if (useSystemVolume && _pulseBus != NULL && + if (settings->property("useSystemVolume").toBool() && _pulseBus != NULL && (operation == WatchConnector::musicVOLUME_UP || operation == WatchConnector::musicVOLUME_DOWN)) { // Query current volume QDBusMessage call = QDBusMessage::createMethodCall("com.Meego.MainVolume2", "/com/meego/mainvolume2", diff --git a/daemon/notificationmanager.cpp b/daemon/notificationmanager.cpp index d983539..d357a3c 100644 --- a/daemon/notificationmanager.cpp +++ b/daemon/notificationmanager.cpp @@ -126,8 +126,7 @@ uint NotificationManager::Notify(const QString &app_name, uint replaces_id, cons setDelayedReply(true); if (app_name == "messageserver5") { - QVariant notificationsEmails = settings->property("notificationsEmails"); - if (!notificationsEmails.isValid() || !notificationsEmails.toBool()) { + if (!settings->property("notificationsEmails").toBool()) { qCDebug(l) << "Ignoring email notification because of setting!"; return 0; } @@ -149,14 +148,12 @@ uint NotificationManager::Notify(const QString &app_name, uint replaces_id, cons QString category = hints.value("category", "").toString(); if (category == "x-nemo.call.missed") { - QVariant notificationsMissedCall = settings->property("notificationsMissedCall"); - if (notificationsMissedCall.isValid() && !notificationsMissedCall.toBool()) { + if (!settings->property("notificationsMissedCall").toBool()) { qCDebug(l) << "Ignoring MissedCall notification because of setting!"; return 0; } } else { - QVariant notificationsCommhistoryd = settings->property("notificationsCommhistoryd"); - if (notificationsCommhistoryd.isValid() && !notificationsCommhistoryd.toBool()) { + if (!settings->property("notificationsCommhistoryd").toBool()) { qCDebug(l) << "Ignoring commhistoryd notification because of setting!"; return 0; } @@ -166,8 +163,7 @@ uint NotificationManager::Notify(const QString &app_name, uint replaces_id, cons ); } } else if (app_name == "harbour-mitakuuluu2-server") { - QVariant notificationsMitakuuluu = settings->property("notificationsMitakuuluu"); - if (notificationsMitakuuluu.isValid() && !notificationsMitakuuluu.toBool()) { + if (!settings->property("notificationsMitakuuluu").toBool()) { qCDebug(l) << "Ignoring mitakuuluu notification because of setting!"; return 0; } @@ -176,8 +172,7 @@ uint NotificationManager::Notify(const QString &app_name, uint replaces_id, cons hints.value("x-nemo-preview-summary", "default").toString() ); } else if (app_name == "twitter-notifications-client") { - QVariant notificationsTwitter = settings->property("notificationsTwitter"); - if (notificationsTwitter.isValid() && !notificationsTwitter.toBool()) { + if (!settings->property("notificationsTwitter").toBool()) { qCDebug(l) << "Ignoring twitter notification because of setting!"; return 0; } @@ -195,14 +190,12 @@ uint NotificationManager::Notify(const QString &app_name, uint replaces_id, cons qCDebug(l) << "MSG Prio:" << prio; - QVariant notificationsAll = settings->property("notificationsAll"); - if ((!notificationsAll.isValid() || !notificationsAll.toBool()) && prio <= 10) { + if (!settings->property("notificationsAll").toBool() && prio <= 10) { qCDebug(l) << "Ignoring notification because of setting! (all)"; return 0; } - QVariant notificationsOther = settings->property("notificationsOther"); - if (notificationsOther.isValid() && !notificationsOther.toBool() && prio < 90) { + if (!settings->property("notificationsOther").toBool() && prio < 90) { qCDebug(l) << "Ignoring notification because of setting! (other)"; return 0; } diff --git a/daemon/settings.h b/daemon/settings.h index 3c38473..a247dc5 100644 --- a/daemon/settings.h +++ b/daemon/settings.h @@ -39,8 +39,23 @@ class Settings : public MDConfGroup public: explicit Settings(QObject *parent = 0) : - MDConfGroup("/org/pebbled/settings", parent, BindProperties) - { resolveMetaObject(); } + MDConfGroup("/org/pebbled/settings", parent, BindProperties), + transliterateMessage(false), + useSystemVolume(true), + incomingCallNotification(true), + notificationsCommhistoryd(true), + notificationsMissedCall(true), + notificationsEmails(false), + notificationsMitakuuluu(true), + notificationsTwitter(true), + notificationsFacebook(true), + notificationsOther(true), + notificationsAll(false) + { + resolveMetaObject(); + QMetaObject::invokeMethod(this, "propertyChanged", Qt::DirectConnection); + sync(); + } signals: void profileWhenConnectedChanged(); diff --git a/daemon/watchconnector.cpp b/daemon/watchconnector.cpp index 2c17a0b..09006c0 100644 --- a/daemon/watchconnector.cpp +++ b/daemon/watchconnector.cpp @@ -1,6 +1,12 @@ #include <QDateTime> #include <QMetaEnum> #include <QDebugStateSaver> +#include <QBluetoothLocalDevice> +#include <QDBusConnection> +#include <QDBusMessage> +#include <QDBusReply> +#include <QDBusArgument> +#include <QDBusObjectPath> #include "unpacker.h" #include "watchconnector.h" @@ -64,23 +70,28 @@ bool WatchConnector::WatchVersions::isEmpty() const } WatchConnector::WatchConnector(QObject *parent) : - QObject(parent), l(metaObject()->className()), socket(nullptr), is_connected(false) + QObject(parent), l(metaObject()->className()), + socket(nullptr), is_connected(false), currentPebble(0), _last_address(0) { reconnectTimer.setSingleShot(true); - connect(&reconnectTimer, SIGNAL(timeout()), SLOT(reconnect())); + QObject::connect(&reconnectTimer, SIGNAL(timeout()), SLOT(connect())); timeSyncTimer.setSingleShot(true); - connect(&timeSyncTimer, SIGNAL(timeout()), SLOT(time())); + QObject::connect(&timeSyncTimer, SIGNAL(timeout()), SLOT(time())); timeSyncTimer.setInterval(4 * 60 * 60 * 1000); // sync time every 4 hours firmwareMapping.insert(UNKNOWN, "unknown"); - firmwareMapping.insert(PEBBLE_ONE_EV1, "ev1"); - firmwareMapping.insert(PEBBLE_ONE_EV2, "ev2"); - firmwareMapping.insert(PEBBLE_ONE_EV2_3, "ev2_3"); - firmwareMapping.insert(PEBBLE_ONE_EV2_4, "ev2_4"); - firmwareMapping.insert(PEBBLE_ONE_POINT_FIVE, "v1_5"); - firmwareMapping.insert(PEBBLE_TWO_POINT_ZERO, "v2_0"); - firmwareMapping.insert(PEBBLE_ONE_BIGBOARD_2, "bb2"); - firmwareMapping.insert(PEBBLE_ONE_BIGBOARD, "bigboard"); + firmwareMapping.insert(TINTIN_EV1, "ev1"); + firmwareMapping.insert(TINTIN_EV2, "ev2"); + firmwareMapping.insert(TINTIN_EV2_3, "ev2_3"); + firmwareMapping.insert(TINTIN_EV2_4, "ev2_4"); + firmwareMapping.insert(TINTIN_V1_5, "v1_5"); + firmwareMapping.insert(BIANCA, "v2_0"); + firmwareMapping.insert(SNOWY_EVT2, "snowy_evt2"); + firmwareMapping.insert(SNOWY_DVT, "snowy_dvt"); + firmwareMapping.insert(TINTIN_BB, "bigboard"); + firmwareMapping.insert(TINTIN_BB2, "bb2"); + firmwareMapping.insert(SNOWY_BB, "snowy_bb"); + firmwareMapping.insert(SNOWY_BB2, "snowy_bb2"); setEndpointHandler(watchVERSION, [this](const QByteArray &data) { Unpacker u(data); @@ -124,28 +135,71 @@ WatchConnector::~WatchConnector() { } -void WatchConnector::deviceDiscovered(const QBluetoothDeviceInfo &device) +//dbus-send --system --dest=org.bluez --print-reply / org.bluez.Manager.ListAdapters +//dbus-send --system --dest=org.bluez --print-reply $path org.bluez.Adapter.GetProperties +//dbus-send --system --dest=org.bluez --print-reply $devpath org.bluez.Device.GetProperties +//dbus-send --system --dest=org.bluez --print-reply $devpath org.bluez.Input.Connect +bool WatchConnector::findPebbles() { - //FIXME TODO: Configurable - if (device.name().startsWith("Pebble")) { - qCDebug(l) << "Found Pebble:" << device.name() << '(' << device.address().toString() << ')'; - handleWatch(device.name(), device.address().toString()); - } else { - qCDebug(l) << "Found other device:" << device.name() << '(' << device.address().toString() << ')'; + pebbles.clear(); + currentPebble = 0; + + QDBusConnection system = QDBusConnection::systemBus(); + + QDBusReply<QList<QDBusObjectPath>> ListAdaptersReply = system.call( + QDBusMessage::createMethodCall("org.bluez", "/", "org.bluez.Manager", + "ListAdapters")); + if (not ListAdaptersReply.isValid()) { + qCCritical(l) << ListAdaptersReply.error().message(); + return false; } -} -void WatchConnector::deviceConnect(const QString &name, const QString &address) -{ - if (name.startsWith("Pebble")) handleWatch(name, address); -} + QList<QDBusObjectPath> adapters = ListAdaptersReply.value(); -void WatchConnector::reconnect() -{ - qCDebug(l) << "reconnect" << _last_name; - if (!_last_name.isEmpty() && !_last_address.isEmpty()) { - deviceConnect(_last_name, _last_address); + if (adapters.isEmpty()) { + qCDebug(l) << "No BT adapters found"; + return false; + } + + QDBusReply<QVariantMap> AdapterPropertiesReply = system.call( + QDBusMessage::createMethodCall("org.bluez", adapters[0].path(), "org.bluez.Adapter", + "GetProperties")); + if (not AdapterPropertiesReply.isValid()) { + qCCritical(l) << AdapterPropertiesReply.error().message(); + return false; + } + + QList<QDBusObjectPath> devices; + AdapterPropertiesReply.value()["Devices"].value<QDBusArgument>() >> devices; + + foreach (QDBusObjectPath path, devices) { + QDBusReply<QVariantMap> DevicePropertiesReply = system.call( + QDBusMessage::createMethodCall("org.bluez", path.path(), "org.bluez.Device", + "GetProperties")); + if (not DevicePropertiesReply.isValid()) { + qCCritical(l) << DevicePropertiesReply.error().message(); + continue; + } + + const QVariantMap &dict = DevicePropertiesReply.value(); + + QString tmp = dict["Name"].toString(); + qCDebug(l) << "Found BT device:" << tmp; + if (tmp.startsWith("Pebble")) { + qCDebug(l) << "Found Pebble:" << tmp; + QBluetoothAddress addr(dict["Address"].toString()); + QBluetoothLocalDevice dev; + if (dev.pairingStatus(addr) == QBluetoothLocalDevice::AuthorizedPaired) { + pebbles.insert(dict["Name"].toString(), addr); + } + } } + + if (pebbles.size()) { + scheduleReconnect(); + } + + return true; } void WatchConnector::disconnect() @@ -158,11 +212,23 @@ void WatchConnector::disconnect() qCDebug(l) << "stopped timers"; } -void WatchConnector::handleWatch(const QString &name, const QString &address) +void WatchConnector::connect() { - qCDebug(l) << "handleWatch" << name << address; + if (currentPebble >= pebbles.count()) { + currentPebble = 0; + } + + QString _name = pebbles.keys().at(currentPebble); + QBluetoothAddress _address = pebbles.value(_name); + + qCDebug(l) << "connect watch" << currentPebble << _name << _address.toString(); reconnectTimer.stop(); + if (_address.isNull()) { + qCWarning(l) << "No known pebble"; + return; + } + // Check if bluetooth is on QBluetoothLocalDevice host; bool btOff = host.hostMode() == QBluetoothLocalDevice::HostPoweredOff; @@ -177,20 +243,18 @@ void WatchConnector::handleWatch(const QString &name, const QString &address) socket->deleteLater(); } - _last_name = name; - _last_address = address; _versions.clear(); qCDebug(l) << "Creating socket"; socket = new QBluetoothSocket(QBluetoothServiceInfo::RfcommProtocol); - connect(socket, SIGNAL(readyRead()), SLOT(onReadSocket())); - connect(socket, SIGNAL(bytesWritten(qint64)), SLOT(onBytesWritten(qint64))); - connect(socket, SIGNAL(connected()), SLOT(onConnected())); - connect(socket, SIGNAL(disconnected()), SLOT(onDisconnected())); - connect(socket, SIGNAL(error(QBluetoothSocket::SocketError)), this, SLOT(onError(QBluetoothSocket::SocketError))); + QObject::connect(socket, SIGNAL(readyRead()), SLOT(onReadSocket())); + QObject::connect(socket, SIGNAL(bytesWritten(qint64)), SLOT(onBytesWritten(qint64))); + QObject::connect(socket, SIGNAL(connected()), SLOT(onConnected())); + QObject::connect(socket, SIGNAL(disconnected()), SLOT(onDisconnected())); + QObject::connect(socket, SIGNAL(error(QBluetoothSocket::SocketError)), this, SLOT(onError(QBluetoothSocket::SocketError))); // FIXME: Assuming port 1 (with Pebble) - socket->connectToService(QBluetoothAddress(address), 1); + socket->connectToService(_address, 1); } QString WatchConnector::decodeEndpoint(uint val) @@ -315,7 +379,9 @@ void WatchConnector::onConnected() } sendMessage(watchVERSION, QByteArray(1, 0)); emit connectedChanged(); - if (name() != _last_name) emit nameChanged(); + quint64 new_address = address().toUInt64(); + if (new_address != _last_address) emit pebbleChanged(); + _last_address = new_address; time(); } } @@ -354,7 +420,11 @@ void WatchConnector::scheduleReconnect() void WatchConnector::onError(QBluetoothSocket::SocketError error) { if (error == QBluetoothSocket::UnknownSocketError) { - qCDebug(l) << error << socket->errorString(); + QString errorString = socket->errorString(); + qCDebug(l) << error << errorString; + if (errorString.endsWith(" down")) { + currentPebble++; + } } else { qCCritical(l) << "error connecting Pebble:" << error << socket->errorString(); } @@ -365,7 +435,7 @@ void WatchConnector::sendData(const QByteArray &data) writeData.append(data); if (socket == nullptr) { qCDebug(l) << "no socket - reconnecting"; - reconnect(); + connect(); } else if (is_connected) { qCDebug(l) << "writing" << data.length() << "bytes to socket"; if (PROTOCOL_DEBUG) qCDebug(l) << data.toHex(); diff --git a/daemon/watchconnector.h b/daemon/watchconnector.h index f9576a3..fa65f6b 100644 --- a/daemon/watchconnector.h +++ b/daemon/watchconnector.h @@ -8,10 +8,8 @@ #include <QStringList> #include <QTimer> #include <QDateTime> -#include <QBluetoothDeviceInfo> -#include <QBluetoothLocalDevice> #include <QBluetoothSocket> -#include <QBluetoothServiceInfo> +#include <QBluetoothAddress> #include <QLoggingCategory> class WatchConnector : public QObject @@ -21,7 +19,7 @@ class WatchConnector : public QObject Q_ENUMS(Endpoint) - Q_PROPERTY(QString name READ name NOTIFY nameChanged) + Q_PROPERTY(QString name READ name NOTIFY pebbleChanged) Q_PROPERTY(QString connected READ isConnected NOTIFY connectedChanged) public: @@ -150,14 +148,19 @@ public: enum HardwareRevision { UNKNOWN = 0, - PEBBLE_ONE_EV1 = 1, - PEBBLE_ONE_EV2 = 2, - PEBBLE_ONE_EV2_3 = 3, - PEBBLE_ONE_EV2_4 = 4, - PEBBLE_ONE_POINT_FIVE = 5, - PEBBLE_TWO_POINT_ZERO = 6, - PEBBLE_ONE_BIGBOARD_2 = 254, - PEBBLE_ONE_BIGBOARD = 255 + TINTIN_EV1 = 1, + TINTIN_EV2 = 2, + TINTIN_EV2_3 = 3, + TINTIN_EV2_4 = 4, + TINTIN_V1_5 = 5, + BIANCA = 6, + SNOWY_EVT2 = 7, + SNOWY_DVT = 8, + + TINTIN_BB = 0xFF, + TINTIN_BB2 = 0xFE, + SNOWY_BB = 0xFD, + SNOWY_BB2 = 0xFC }; QMap<HardwareRevision, QString> firmwareMapping; @@ -200,7 +203,8 @@ public: virtual ~WatchConnector(); inline bool isConnected() const { return is_connected; } - inline QString name() const { return socket != nullptr ? socket->peerName() : ""; } + inline QString name() const { return pebbles.keys(address()).at(0); } + inline QBluetoothAddress address() const { return socket != nullptr ? socket->peerAddress() : QBluetoothAddress(); } inline WatchVersions versions() const { return _versions; } void setEndpointHandler(uint endpoint, const EndpointHandlerFunc &func); @@ -210,15 +214,15 @@ public: static QString decodeEndpoint(uint val); signals: - void nameChanged(); + void pebbleChanged(); void versionsChanged(); void connectedChanged(); public slots: - void deviceConnect(const QString &name, const QString &address); + bool findPebbles(); void scheduleReconnect(); + void connect(); void disconnect(); - void reconnect(); void sendMessage(uint endpoint, const QByteArray &data, const EndpointHandlerFunc &callback = EndpointHandlerFunc()); void ping(uint cookie); @@ -243,8 +247,6 @@ public slots: void endPhoneCall(uint cookie=0); private slots: - void deviceDiscovered(const QBluetoothDeviceInfo&); - void handleWatch(const QString &name, const QString &address); void onReadSocket(); void onBytesWritten(qint64); void onConnected(); @@ -262,8 +264,9 @@ private: QByteArray writeData; QTimer reconnectTimer; QTimer timeSyncTimer; - QString _last_name; - QString _last_address; + QMap<QString,QBluetoothAddress> pebbles; + int currentPebble; + quint64 _last_address; WatchVersions _versions; }; |
