From 67670934bef4ac7f41e6bc336f0ad9516fe2b28d Mon Sep 17 00:00:00 2001 From: Andrew Branson Date: Wed, 13 May 2015 14:10:43 +0200 Subject: Auto-synchronize time Sync on connect, then every four hours while connected. --- daemon/watchconnector.cpp | 7 +++++++ daemon/watchconnector.h | 1 + 2 files changed, 8 insertions(+) (limited to 'daemon') diff --git a/daemon/watchconnector.cpp b/daemon/watchconnector.cpp index a4bfb64..04e9ceb 100644 --- a/daemon/watchconnector.cpp +++ b/daemon/watchconnector.cpp @@ -68,6 +68,9 @@ WatchConnector::WatchConnector(QObject *parent) : { reconnectTimer.setSingleShot(true); connect(&reconnectTimer, SIGNAL(timeout()), SLOT(reconnect())); + timeSyncTimer.setSingleShot(true); + connect(&timeSyncTimer, SIGNAL(timeout()), SLOT(time())); + timeSyncTimer.setInterval(14400000); firmwareMapping.insert(UNKNOWN, "unknown"); firmwareMapping.insert(PEBBLE_ONE_EV1, "ev1"); @@ -151,6 +154,7 @@ void WatchConnector::disconnect() socket->close(); socket->deleteLater(); reconnectTimer.stop(); + timeSyncTimer.stop(); qCDebug(l) << "stopped reconnect timer"; } @@ -312,6 +316,7 @@ void WatchConnector::onConnected() sendMessage(watchVERSION, QByteArray(1, 0)); emit connectedChanged(); if (name() != _last_name) emit nameChanged(); + time(); } } @@ -476,6 +481,7 @@ void WatchConnector::ping(uint cookie) void WatchConnector::time() { + timeSyncTimer.stop(); QByteArray res; QDateTime UTC(QDateTime::currentDateTimeUtc()); QDateTime local(UTC.toLocalTime()); @@ -489,6 +495,7 @@ void WatchConnector::time() res.append((char)((val >> 8) & 0xff)); res.append((char)(val & 0xff)); sendMessage(watchTIME, res); + timeSyncTimer.start(); } QString WatchConnector::timeStamp() diff --git a/daemon/watchconnector.h b/daemon/watchconnector.h index 4e6ed5d..f9576a3 100644 --- a/daemon/watchconnector.h +++ b/daemon/watchconnector.h @@ -261,6 +261,7 @@ private: bool is_connected; QByteArray writeData; QTimer reconnectTimer; + QTimer timeSyncTimer; QString _last_name; QString _last_address; WatchVersions _versions; -- cgit v1.2.3 From a86031160fb3273b1d861f56d66a2e5d191bfed5 Mon Sep 17 00:00:00 2001 From: Andrew Branson Date: Wed, 13 May 2015 14:32:43 +0200 Subject: Stop time sync timer when disconnected. Improve debug --- daemon/watchconnector.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'daemon') diff --git a/daemon/watchconnector.cpp b/daemon/watchconnector.cpp index 04e9ceb..0b0bca1 100644 --- a/daemon/watchconnector.cpp +++ b/daemon/watchconnector.cpp @@ -155,7 +155,7 @@ void WatchConnector::disconnect() socket->deleteLater(); reconnectTimer.stop(); timeSyncTimer.stop(); - qCDebug(l) << "stopped reconnect timer"; + qCDebug(l) << "stopped timers"; } void WatchConnector::handleWatch(const QString &name, const QString &address) @@ -337,7 +337,7 @@ void WatchConnector::onDisconnected() if (not writeData.isEmpty() && reconnectTimer.interval() > RECONNECT_TIMEOUT) { writeData.clear(); // 3rd time around - user is not here, do not bother with resending last message } - + timeSyncTimer.stop(); scheduleReconnect(); } @@ -481,6 +481,7 @@ void WatchConnector::ping(uint cookie) void WatchConnector::time() { + qCDebug(l) << "Synchronizing time"; timeSyncTimer.stop(); QByteArray res; QDateTime UTC(QDateTime::currentDateTimeUtc()); -- cgit v1.2.3 From 2d50346f06e5be31557cb4718ff94cd650c1a210 Mon Sep 17 00:00:00 2001 From: Andrew Branson Date: Thu, 14 May 2015 11:59:46 +0200 Subject: Update watchconnector.cpp --- daemon/watchconnector.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'daemon') diff --git a/daemon/watchconnector.cpp b/daemon/watchconnector.cpp index 0b0bca1..2c17a0b 100644 --- a/daemon/watchconnector.cpp +++ b/daemon/watchconnector.cpp @@ -70,7 +70,7 @@ WatchConnector::WatchConnector(QObject *parent) : connect(&reconnectTimer, SIGNAL(timeout()), SLOT(reconnect())); timeSyncTimer.setSingleShot(true); connect(&timeSyncTimer, SIGNAL(timeout()), SLOT(time())); - timeSyncTimer.setInterval(14400000); + timeSyncTimer.setInterval(4 * 60 * 60 * 1000); // sync time every 4 hours firmwareMapping.insert(UNKNOWN, "unknown"); firmwareMapping.insert(PEBBLE_ONE_EV1, "ev1"); -- cgit v1.2.3