1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-28 04:46:51 +01:00

BUGFIX: Really fix the timestamps now for everyone, everywhere. calculate the correct UTC of different timezones and daylight savings.

This commit is contained in:
Sebastian Kranz 2019-07-12 08:08:52 +02:00
parent 8fce521e99
commit 1cd9a09ce5

View File

@ -76,7 +76,7 @@ public class ZeTimeDeviceSupport extends AbstractBTLEDeviceSupport {
private final GBDeviceEventBatteryInfo batteryCmd = new GBDeviceEventBatteryInfo(); private final GBDeviceEventBatteryInfo batteryCmd = new GBDeviceEventBatteryInfo();
private final GBDeviceEventVersionInfo versionCmd = new GBDeviceEventVersionInfo(); private final GBDeviceEventVersionInfo versionCmd = new GBDeviceEventVersionInfo();
private final GBDeviceEventMusicControl musicCmd = new GBDeviceEventMusicControl(); private final GBDeviceEventMusicControl musicCmd = new GBDeviceEventMusicControl();
private final int sevenHourOffset = 25200; private final int eightHourOffset = 28800;
private byte[] lastMsg; private byte[] lastMsg;
private byte msgPart; private byte msgPart;
private int availableSleepData; private int availableSleepData;
@ -1171,8 +1171,10 @@ public class ZeTimeDeviceSupport extends AbstractBTLEDeviceSupport {
private void handleStepsData(byte[] msg) private void handleStepsData(byte[] msg)
{ {
ZeTimeActivitySample sample = new ZeTimeActivitySample(); ZeTimeActivitySample sample = new ZeTimeActivitySample();
Calendar now = GregorianCalendar.getInstance();
int timestamp = (msg[10] << 24)&0xff000000 | (msg[9] << 16)&0xff0000 | (msg[8] << 8)&0xff00 | (msg[7]&0xff); int timestamp = (msg[10] << 24)&0xff000000 | (msg[9] << 16)&0xff0000 | (msg[8] << 8)&0xff00 | (msg[7]&0xff);
timestamp += sevenHourOffset; // the timestamp from the watch has an offset of seven hours, do not know why... timestamp += eightHourOffset; // the timestamp from the watch has an offset of eight hours, do not know why...
timestamp -= ((now.get(Calendar.ZONE_OFFSET)/1000) + (now.get(Calendar.DST_OFFSET)/1000)); // TimeZone hour + daylight saving
sample.setTimestamp(timestamp); sample.setTimestamp(timestamp);
sample.setSteps((msg[14] << 24)&0xff000000 | (msg[13] << 16)&0xff0000 | (msg[12] << 8)&0xff00 | (msg[11]&0xff)); sample.setSteps((msg[14] << 24)&0xff000000 | (msg[13] << 16)&0xff0000 | (msg[12] << 8)&0xff00 | (msg[11]&0xff));
sample.setCaloriesBurnt((msg[18] << 24)&0xff000000 | (msg[17] << 16)&0xff0000 | (msg[16] << 8)&0xff00 | (msg[15]&0xff)); sample.setCaloriesBurnt((msg[18] << 24)&0xff000000 | (msg[17] << 16)&0xff0000 | (msg[16] << 8)&0xff00 | (msg[15]&0xff));
@ -1217,8 +1219,10 @@ public class ZeTimeDeviceSupport extends AbstractBTLEDeviceSupport {
private void handleSleepData(byte[] msg) private void handleSleepData(byte[] msg)
{ {
ZeTimeActivitySample sample = new ZeTimeActivitySample(); ZeTimeActivitySample sample = new ZeTimeActivitySample();
Calendar now = GregorianCalendar.getInstance();
int timestamp = (msg[10] << 24)&0xff000000 | (msg[9] << 16)&0xff0000 | (msg[8] << 8)&0xff00 | (msg[7]&0xff); int timestamp = (msg[10] << 24)&0xff000000 | (msg[9] << 16)&0xff0000 | (msg[8] << 8)&0xff00 | (msg[7]&0xff);
timestamp += sevenHourOffset; // the timestamp from the watch has an offset of seven hours, do not know why... timestamp += eightHourOffset; // the timestamp from the watch has an offset of eight hours, do not know why...
timestamp -= ((now.get(Calendar.ZONE_OFFSET)/1000) + (now.get(Calendar.DST_OFFSET)/1000)); // TimeZone hour + daylight saving
sample.setTimestamp(timestamp); sample.setTimestamp(timestamp);
if(msg[11] == 0) { if(msg[11] == 0) {
sample.setRawKind(ActivityKind.TYPE_DEEP_SLEEP); sample.setRawKind(ActivityKind.TYPE_DEEP_SLEEP);
@ -1260,8 +1264,10 @@ public class ZeTimeDeviceSupport extends AbstractBTLEDeviceSupport {
private void handleHeartRateData(byte[] msg) private void handleHeartRateData(byte[] msg)
{ {
ZeTimeActivitySample sample = new ZeTimeActivitySample(); ZeTimeActivitySample sample = new ZeTimeActivitySample();
Calendar now = GregorianCalendar.getInstance();
int timestamp = (msg[10] << 24)&0xff000000 | (msg[9] << 16)&0xff0000 | (msg[8] << 8)&0xff00 | (msg[7]&0xff); int timestamp = (msg[10] << 24)&0xff000000 | (msg[9] << 16)&0xff0000 | (msg[8] << 8)&0xff00 | (msg[7]&0xff);
timestamp += sevenHourOffset; // the timestamp from the watch has an offset of seven hours, do not know why... timestamp += eightHourOffset; // the timestamp from the watch has an offset of eight hours, do not know why...
timestamp -= ((now.get(Calendar.ZONE_OFFSET)/1000) + (now.get(Calendar.DST_OFFSET)/1000)); // TimeZone hour + daylight saving
sample.setHeartRate(msg[11]); sample.setHeartRate(msg[11]);
sample.setTimestamp(timestamp); sample.setTimestamp(timestamp);
@ -1278,10 +1284,11 @@ public class ZeTimeDeviceSupport extends AbstractBTLEDeviceSupport {
progressHeartRate = (msg[5]&0xff) | ((msg[6] << 8)&0xff00); progressHeartRate = (msg[5]&0xff) | ((msg[6] << 8)&0xff00);
GB.updateTransferNotification(null, getContext().getString(R.string.busy_task_fetch_activity_data), true, (int) (progressHeartRate *100 / availableHeartRateData), getContext()); GB.updateTransferNotification(null, getContext().getString(R.string.busy_task_fetch_activity_data), true, (int) (progressHeartRate *100 / availableHeartRateData), getContext());
if(((msg[4] << 8)&0xff00 | (msg[3]&0xff)) == 0xe) // if the message is longer than 0x7, than it has to measurements (payload = 0xe) if(((msg[4] << 8)&0xff00 | (msg[3]&0xff)) == 0xe) // if the message is longer than 0x7, than it has two measurements (payload = 0xe)
{ {
timestamp = (msg[17] << 24)&0xff000000 | (msg[16] << 16)&0xff0000 | (msg[15] << 8)&0xff00 | (msg[14]&0xff); timestamp = (msg[17] << 24)&0xff000000 | (msg[16] << 16)&0xff0000 | (msg[15] << 8)&0xff00 | (msg[14]&0xff);
timestamp += sevenHourOffset; // the timestamp from the watch has an offset of seven hours, do not know why... timestamp += eightHourOffset; // the timestamp from the watch has an offset of eight hours, do not know why...
timestamp -= ((now.get(Calendar.ZONE_OFFSET)/1000) + (now.get(Calendar.DST_OFFSET)/1000)); // TimeZone hour + daylight saving
sample.setHeartRate(msg[18]); sample.setHeartRate(msg[18]);
sample.setTimestamp(timestamp); sample.setTimestamp(timestamp);