mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-12-25 10:05:49 +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.MINUTE, 0);
|
||||
sampleCal.set(Calendar.SECOND, 0);
|
||||
sampleCal.set(Calendar.MILLISECOND, 0);
|
||||
int calories = BLETypeConversions.toUint16(value[7], value[8]);
|
||||
int steps = BLETypeConversions.toUint16(value[9], value[10]);
|
||||
int distance = BLETypeConversions.toUint16(value[11], value[12]);
|
||||
@ -217,6 +218,8 @@ public class ColmiR0xPacketHandler {
|
||||
LOG.info("Received initial stress history response");
|
||||
} else {
|
||||
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 minutesInPreviousPackets = 0;
|
||||
if (stressPacketNr > 1) {
|
||||
@ -271,6 +274,7 @@ public class ColmiR0xPacketHandler {
|
||||
syncingDay.add(Calendar.DAY_OF_MONTH, 0 - spo2_days_ago);
|
||||
syncingDay.set(Calendar.MINUTE, 0);
|
||||
syncingDay.set(Calendar.SECOND, 0);
|
||||
syncingDay.set(Calendar.MILLISECOND, 0);
|
||||
index++;
|
||||
for (int hour=0; hour<=23; 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.MINUTE, 0);
|
||||
sessionStart.set(Calendar.SECOND, 0);
|
||||
sessionStart.set(Calendar.MILLISECOND, 0);
|
||||
if (sleepStart > sleepEnd) {
|
||||
// Sleep started a day earlier, so before midnight
|
||||
sessionStart.add(Calendar.DAY_OF_MONTH, -1);
|
||||
@ -345,6 +350,7 @@ public class ColmiR0xPacketHandler {
|
||||
sessionEnd.set(Calendar.HOUR_OF_DAY, 0);
|
||||
sessionEnd.set(Calendar.MINUTE, sleepEnd);
|
||||
sessionEnd.set(Calendar.SECOND, 0);
|
||||
sessionEnd.set(Calendar.MILLISECOND, 0);
|
||||
LOG.info("Sleep session starts at {} and ends at {}", sessionStart.getTime(), sessionEnd.getTime());
|
||||
// Build sample object to persist
|
||||
final ColmiSleepSessionSample sessionSample = new ColmiSleepSessionSample();
|
||||
|
@ -216,6 +216,7 @@ public class ColmiR0xDeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
packetsTotalNr = value[2];
|
||||
LOG.info("HR history packet {} out of total {}", hrPacketNr, packetsTotalNr);
|
||||
} else {
|
||||
LOG.info("HR history packet {} out of total {} (data for {}:00-{}:00)", hrPacketNr, packetsTotalNr, hrPacketNr-1, hrPacketNr);
|
||||
Calendar sampleCal = (Calendar) syncingDay.clone();
|
||||
int startValue = hrPacketNr == 1 ? 6 : 2; // packet 1 contains the sync-from timestamp in bytes 2-5
|
||||
int minutesInPreviousPackets = 0;
|
||||
@ -246,7 +247,6 @@ public class ColmiR0xDeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
}
|
||||
}
|
||||
}
|
||||
LOG.info("HR history packet {}", hrPacketNr);
|
||||
if (hrPacketNr == packetsTotalNr - 1) {
|
||||
getDevice().unsetBusyTask();
|
||||
getDevice().sendDeviceUpdateIntent(getContext());
|
||||
@ -595,6 +595,7 @@ public class ColmiR0xDeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
syncingDay.set(Calendar.HOUR_OF_DAY, 0);
|
||||
syncingDay.set(Calendar.MINUTE, 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});
|
||||
LOG.info("Fetch historical activity data request sent: {}", StringUtils.bytesToHex(activityHistoryRequest));
|
||||
sendWrite("activityHistoryRequest", activityHistoryRequest);
|
||||
@ -608,8 +609,9 @@ public class ColmiR0xDeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
syncingDay.add(Calendar.DAY_OF_MONTH, 0 - daysAgo);
|
||||
syncingDay.set(Calendar.HOUR_OF_DAY, 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);
|
||||
hrHistoryRequestBB.order(ByteOrder.LITTLE_ENDIAN);
|
||||
hrHistoryRequestBB.put(0, ColmiR0xConstants.CMD_SYNC_HEART_RATE);
|
||||
|
Loading…
Reference in New Issue
Block a user