mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2025-01-13 11:17:33 +01:00
Colmi R0x: Normalize timestamps of all received health data
This fixes the duplicate samples reported in #4209, and possibly even the originally reported issue of multiple days showing the same HR data in the charts.
This commit is contained in:
parent
873a044a69
commit
9abcb87f1f
@ -174,6 +174,7 @@ public class ColmiR0xPacketHandler {
|
|||||||
sampleCal.set(Calendar.HOUR_OF_DAY, value[4] / 4); // And the hour is transmitted as nth quarter of the day...
|
sampleCal.set(Calendar.HOUR_OF_DAY, value[4] / 4); // And the hour is transmitted as nth quarter of the day...
|
||||||
sampleCal.set(Calendar.MINUTE, 0);
|
sampleCal.set(Calendar.MINUTE, 0);
|
||||||
sampleCal.set(Calendar.SECOND, 0);
|
sampleCal.set(Calendar.SECOND, 0);
|
||||||
|
sampleCal.set(Calendar.MILLISECOND, 0);
|
||||||
int calories = BLETypeConversions.toUint16(value[7], value[8]);
|
int calories = BLETypeConversions.toUint16(value[7], value[8]);
|
||||||
int steps = BLETypeConversions.toUint16(value[9], value[10]);
|
int steps = BLETypeConversions.toUint16(value[9], value[10]);
|
||||||
int distance = BLETypeConversions.toUint16(value[11], value[12]);
|
int distance = BLETypeConversions.toUint16(value[11], value[12]);
|
||||||
@ -217,6 +218,8 @@ public class ColmiR0xPacketHandler {
|
|||||||
LOG.info("Received initial stress history response");
|
LOG.info("Received initial stress history response");
|
||||||
} else {
|
} else {
|
||||||
Calendar sampleCal = Calendar.getInstance();
|
Calendar sampleCal = Calendar.getInstance();
|
||||||
|
sampleCal.set(Calendar.SECOND, 0);
|
||||||
|
sampleCal.set(Calendar.MILLISECOND, 0);
|
||||||
int startValue = stressPacketNr == 1 ? 3 : 2; // packet 1 data starts at byte 3, others at byte 2
|
int startValue = stressPacketNr == 1 ? 3 : 2; // packet 1 data starts at byte 3, others at byte 2
|
||||||
int minutesInPreviousPackets = 0;
|
int minutesInPreviousPackets = 0;
|
||||||
if (stressPacketNr > 1) {
|
if (stressPacketNr > 1) {
|
||||||
@ -271,6 +274,7 @@ public class ColmiR0xPacketHandler {
|
|||||||
syncingDay.add(Calendar.DAY_OF_MONTH, 0 - spo2_days_ago);
|
syncingDay.add(Calendar.DAY_OF_MONTH, 0 - spo2_days_ago);
|
||||||
syncingDay.set(Calendar.MINUTE, 0);
|
syncingDay.set(Calendar.MINUTE, 0);
|
||||||
syncingDay.set(Calendar.SECOND, 0);
|
syncingDay.set(Calendar.SECOND, 0);
|
||||||
|
syncingDay.set(Calendar.MILLISECOND, 0);
|
||||||
index++;
|
index++;
|
||||||
for (int hour=0; hour<=23; hour++) {
|
for (int hour=0; hour<=23; hour++) {
|
||||||
syncingDay.set(Calendar.HOUR_OF_DAY, hour);
|
syncingDay.set(Calendar.HOUR_OF_DAY, hour);
|
||||||
@ -331,6 +335,7 @@ public class ColmiR0xPacketHandler {
|
|||||||
sessionStart.set(Calendar.HOUR_OF_DAY, 0);
|
sessionStart.set(Calendar.HOUR_OF_DAY, 0);
|
||||||
sessionStart.set(Calendar.MINUTE, 0);
|
sessionStart.set(Calendar.MINUTE, 0);
|
||||||
sessionStart.set(Calendar.SECOND, 0);
|
sessionStart.set(Calendar.SECOND, 0);
|
||||||
|
sessionStart.set(Calendar.MILLISECOND, 0);
|
||||||
if (sleepStart > sleepEnd) {
|
if (sleepStart > sleepEnd) {
|
||||||
// Sleep started a day earlier, so before midnight
|
// Sleep started a day earlier, so before midnight
|
||||||
sessionStart.add(Calendar.DAY_OF_MONTH, -1);
|
sessionStart.add(Calendar.DAY_OF_MONTH, -1);
|
||||||
@ -345,6 +350,7 @@ public class ColmiR0xPacketHandler {
|
|||||||
sessionEnd.set(Calendar.HOUR_OF_DAY, 0);
|
sessionEnd.set(Calendar.HOUR_OF_DAY, 0);
|
||||||
sessionEnd.set(Calendar.MINUTE, sleepEnd);
|
sessionEnd.set(Calendar.MINUTE, sleepEnd);
|
||||||
sessionEnd.set(Calendar.SECOND, 0);
|
sessionEnd.set(Calendar.SECOND, 0);
|
||||||
|
sessionEnd.set(Calendar.MILLISECOND, 0);
|
||||||
LOG.info("Sleep session starts at {} and ends at {}", sessionStart.getTime(), sessionEnd.getTime());
|
LOG.info("Sleep session starts at {} and ends at {}", sessionStart.getTime(), sessionEnd.getTime());
|
||||||
// Build sample object to persist
|
// Build sample object to persist
|
||||||
final ColmiSleepSessionSample sessionSample = new ColmiSleepSessionSample();
|
final ColmiSleepSessionSample sessionSample = new ColmiSleepSessionSample();
|
||||||
|
@ -216,6 +216,7 @@ public class ColmiR0xDeviceSupport extends AbstractBTLEDeviceSupport {
|
|||||||
packetsTotalNr = value[2];
|
packetsTotalNr = value[2];
|
||||||
LOG.info("HR history packet {} out of total {}", hrPacketNr, packetsTotalNr);
|
LOG.info("HR history packet {} out of total {}", hrPacketNr, packetsTotalNr);
|
||||||
} else {
|
} else {
|
||||||
|
LOG.info("HR history packet {} out of total {} (data for {}:00-{}:00)", hrPacketNr, packetsTotalNr, hrPacketNr-1, hrPacketNr);
|
||||||
Calendar sampleCal = (Calendar) syncingDay.clone();
|
Calendar sampleCal = (Calendar) syncingDay.clone();
|
||||||
int startValue = hrPacketNr == 1 ? 6 : 2; // packet 1 contains the sync-from timestamp in bytes 2-5
|
int startValue = hrPacketNr == 1 ? 6 : 2; // packet 1 contains the sync-from timestamp in bytes 2-5
|
||||||
int minutesInPreviousPackets = 0;
|
int minutesInPreviousPackets = 0;
|
||||||
@ -246,7 +247,6 @@ public class ColmiR0xDeviceSupport extends AbstractBTLEDeviceSupport {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
LOG.info("HR history packet {}", hrPacketNr);
|
|
||||||
if (hrPacketNr == packetsTotalNr - 1) {
|
if (hrPacketNr == packetsTotalNr - 1) {
|
||||||
getDevice().unsetBusyTask();
|
getDevice().unsetBusyTask();
|
||||||
getDevice().sendDeviceUpdateIntent(getContext());
|
getDevice().sendDeviceUpdateIntent(getContext());
|
||||||
@ -595,6 +595,7 @@ public class ColmiR0xDeviceSupport extends AbstractBTLEDeviceSupport {
|
|||||||
syncingDay.set(Calendar.HOUR_OF_DAY, 0);
|
syncingDay.set(Calendar.HOUR_OF_DAY, 0);
|
||||||
syncingDay.set(Calendar.MINUTE, 0);
|
syncingDay.set(Calendar.MINUTE, 0);
|
||||||
syncingDay.set(Calendar.SECOND, 0);
|
syncingDay.set(Calendar.SECOND, 0);
|
||||||
|
syncingDay.set(Calendar.MILLISECOND, 0);
|
||||||
byte[] activityHistoryRequest = buildPacket(new byte[]{ColmiR0xConstants.CMD_SYNC_ACTIVITY, (byte) daysAgo, 0x0f, 0x00, 0x5f, 0x01});
|
byte[] activityHistoryRequest = buildPacket(new byte[]{ColmiR0xConstants.CMD_SYNC_ACTIVITY, (byte) daysAgo, 0x0f, 0x00, 0x5f, 0x01});
|
||||||
LOG.info("Fetch historical activity data request sent: {}", StringUtils.bytesToHex(activityHistoryRequest));
|
LOG.info("Fetch historical activity data request sent: {}", StringUtils.bytesToHex(activityHistoryRequest));
|
||||||
sendWrite("activityHistoryRequest", activityHistoryRequest);
|
sendWrite("activityHistoryRequest", activityHistoryRequest);
|
||||||
@ -608,8 +609,9 @@ public class ColmiR0xDeviceSupport extends AbstractBTLEDeviceSupport {
|
|||||||
syncingDay.add(Calendar.DAY_OF_MONTH, 0 - daysAgo);
|
syncingDay.add(Calendar.DAY_OF_MONTH, 0 - daysAgo);
|
||||||
syncingDay.set(Calendar.HOUR_OF_DAY, 0);
|
syncingDay.set(Calendar.HOUR_OF_DAY, 0);
|
||||||
syncingDay.set(Calendar.MINUTE, 0);
|
syncingDay.set(Calendar.MINUTE, 0);
|
||||||
syncingDay.set(Calendar.SECOND, 0);
|
|
||||||
}
|
}
|
||||||
|
syncingDay.set(Calendar.SECOND, 0);
|
||||||
|
syncingDay.set(Calendar.MILLISECOND, 0);
|
||||||
ByteBuffer hrHistoryRequestBB = ByteBuffer.allocate(5);
|
ByteBuffer hrHistoryRequestBB = ByteBuffer.allocate(5);
|
||||||
hrHistoryRequestBB.order(ByteOrder.LITTLE_ENDIAN);
|
hrHistoryRequestBB.order(ByteOrder.LITTLE_ENDIAN);
|
||||||
hrHistoryRequestBB.put(0, ColmiR0xConstants.CMD_SYNC_HEART_RATE);
|
hrHistoryRequestBB.put(0, ColmiR0xConstants.CMD_SYNC_HEART_RATE);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user