1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-06-20 20:10:15 +02:00

Mi Band 8: Sleep details parser (very very wip)

This commit is contained in:
José Rebelo 2023-10-20 00:05:10 +01:00
parent aead518e05
commit 8333b8b8d8
2 changed files with 56 additions and 1 deletions

View File

@ -23,6 +23,7 @@ import org.slf4j.LoggerFactory;
import nodomain.freeyourgadget.gadgetbridge.service.devices.xiaomi.XiaomiSupport;
import nodomain.freeyourgadget.gadgetbridge.service.devices.xiaomi.activity.impl.DailyDetailsParser;
import nodomain.freeyourgadget.gadgetbridge.service.devices.xiaomi.activity.impl.SleepDetailsParser;
public abstract class XiaomiActivityParser {
private static final Logger LOG = LoggerFactory.getLogger(XiaomiActivityParser.class);
@ -53,7 +54,10 @@ public abstract class XiaomiActivityParser {
break;
case ACTIVITY_SLEEP:
// TODO
if (fileId.getDetailType() == XiaomiActivityFileId.DetailType.DETAILS) {
return new SleepDetailsParser();
}
break;
}

View File

@ -0,0 +1,51 @@
/* Copyright (C) 2023 José Rebelo
This file is part of Gadgetbridge.
Gadgetbridge is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Gadgetbridge is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
package nodomain.freeyourgadget.gadgetbridge.service.devices.xiaomi.activity.impl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import nodomain.freeyourgadget.gadgetbridge.service.devices.xiaomi.XiaomiSupport;
import nodomain.freeyourgadget.gadgetbridge.service.devices.xiaomi.activity.XiaomiActivityFileId;
import nodomain.freeyourgadget.gadgetbridge.service.devices.xiaomi.activity.XiaomiActivityParser;
public class SleepDetailsParser extends XiaomiActivityParser {
private static final Logger LOG = LoggerFactory.getLogger(SleepDetailsParser.class);
@Override
public boolean parse(final XiaomiSupport support, final XiaomiActivityFileId fileId, final byte[] bytes) {
if (fileId.getVersion() != 2) {
LOG.warn("Unknown sleep details version {}", fileId.getVersion());
return false;
}
final ByteBuffer buf = ByteBuffer.wrap(bytes).order(ByteOrder.LITTLE_ENDIAN);
buf.get(); // header ? 0xF0
buf.get(); // ?
final int bedTime = buf.getInt();
final int wakeupTime = buf.getInt();
LOG.info("Bed time: {}, wake up time: {}", bedTime, wakeupTime);
// TODO everything else...
return false;
}
}