mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-12-24 17:45:50 +01:00
Decode a bit more for new acticity summaries (Bip S)
This also adds disabled code to create a binary dump for better analysis
This commit is contained in:
parent
3bff745b38
commit
e208549d1d
@ -26,12 +26,16 @@ import org.json.JSONObject;
|
|||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.nio.ByteOrder;
|
import java.nio.ByteOrder;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.GregorianCalendar;
|
import java.util.GregorianCalendar;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.Logging;
|
import nodomain.freeyourgadget.gadgetbridge.Logging;
|
||||||
@ -47,6 +51,7 @@ import nodomain.freeyourgadget.gadgetbridge.service.btle.BLETypeConversions;
|
|||||||
import nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder;
|
import nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.HuamiSportsActivityType;
|
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.HuamiSportsActivityType;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.HuamiSupport;
|
import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.HuamiSupport;
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.util.FileUtils;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.util.GB;
|
import nodomain.freeyourgadget.gadgetbridge.util.GB;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -167,9 +172,21 @@ public class FetchSportsSummaryOperation extends AbstractFetchOperation {
|
|||||||
private BaseActivitySummary parseSummary(ByteArrayOutputStream stream) {
|
private BaseActivitySummary parseSummary(ByteArrayOutputStream stream) {
|
||||||
BaseActivitySummary summary = new BaseActivitySummary();
|
BaseActivitySummary summary = new BaseActivitySummary();
|
||||||
|
|
||||||
|
boolean dumptofile = false;
|
||||||
|
if (dumptofile) {
|
||||||
|
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd-hhmmss", Locale.US);
|
||||||
|
String filename = "rawsummary_" + dateFormat.format(new Date()) + ".bin";
|
||||||
|
try {
|
||||||
|
File dir = FileUtils.getExternalFilesDir();
|
||||||
|
File outputFile = new File(dir, filename);
|
||||||
|
FileUtils.copyStreamToFile(new ByteArrayInputStream(stream.toByteArray()), outputFile);
|
||||||
|
} catch (IOException e) {
|
||||||
|
LOG.warn("could not create file");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ByteBuffer buffer = ByteBuffer.wrap(stream.toByteArray()).order(ByteOrder.LITTLE_ENDIAN);
|
ByteBuffer buffer = ByteBuffer.wrap(stream.toByteArray()).order(ByteOrder.LITTLE_ENDIAN);
|
||||||
// summary.setVersion(BLETypeConversions.toUnsigned(buffer.getShort()));
|
|
||||||
short version = buffer.getShort(); // version
|
short version = buffer.getShort(); // version
|
||||||
LOG.debug("Got sport summary version " + version + " total bytes=" + buffer.capacity());
|
LOG.debug("Got sport summary version " + version + " total bytes=" + buffer.capacity());
|
||||||
int activityKind = ActivityKind.TYPE_UNKNOWN;
|
int activityKind = ActivityKind.TYPE_UNKNOWN;
|
||||||
@ -222,6 +239,9 @@ public class FetchSportsSummaryOperation extends AbstractFetchOperation {
|
|||||||
float averageStride;
|
float averageStride;
|
||||||
short averageHR;
|
short averageHR;
|
||||||
short averageKMPaceSeconds;
|
short averageKMPaceSeconds;
|
||||||
|
int ascentSeconds = 0;
|
||||||
|
int descentSeconds = 0;
|
||||||
|
int flatSeconds = 0;
|
||||||
|
|
||||||
// Just assuming, Bip has 259 which seems like 256+x
|
// Just assuming, Bip has 259 which seems like 256+x
|
||||||
// Bip S now has 518 so assuming 512+x, might be wrong
|
// Bip S now has 518 so assuming 512+x, might be wrong
|
||||||
@ -251,6 +271,19 @@ public class FetchSportsSummaryOperation extends AbstractFetchOperation {
|
|||||||
averageKMPaceSeconds = buffer.getShort();
|
averageKMPaceSeconds = buffer.getShort();
|
||||||
averageStride = buffer.getShort();
|
averageStride = buffer.getShort();
|
||||||
buffer.getShort(); // unknown
|
buffer.getShort(); // unknown
|
||||||
|
|
||||||
|
if (activityKind == ActivityKind.TYPE_CYCLING || activityKind == ActivityKind.TYPE_RUNNING) {
|
||||||
|
// this had nonsense data with treadmill on bip s, need to test it with running
|
||||||
|
// for cycling it seems to work... hmm...
|
||||||
|
// 28 bytes
|
||||||
|
buffer.getInt(); // unknown
|
||||||
|
buffer.getInt(); // unknown
|
||||||
|
ascentSeconds = buffer.getInt() / 1000; //ms?
|
||||||
|
buffer.getInt(); // unknown;
|
||||||
|
descentSeconds = buffer.getInt() / 1000; //ms?
|
||||||
|
buffer.getInt(); // unknown;
|
||||||
|
flatSeconds = buffer.getInt() / 1000; // ms?
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
distanceMeters = buffer.getFloat();
|
distanceMeters = buffer.getFloat();
|
||||||
ascentMeters = buffer.getFloat();
|
ascentMeters = buffer.getFloat();
|
||||||
@ -295,11 +328,11 @@ public class FetchSportsSummaryOperation extends AbstractFetchOperation {
|
|||||||
// 28 bytes
|
// 28 bytes
|
||||||
buffer.getInt(); // unknown
|
buffer.getInt(); // unknown
|
||||||
buffer.getInt(); // unknown
|
buffer.getInt(); // unknown
|
||||||
int ascentSeconds = buffer.getInt() / 1000; //ms?
|
ascentSeconds = buffer.getInt() / 1000; //ms?
|
||||||
buffer.getInt(); // unknown;
|
buffer.getInt(); // unknown;
|
||||||
int descentSeconds = buffer.getInt() / 1000; //ms?
|
descentSeconds = buffer.getInt() / 1000; //ms?
|
||||||
buffer.getInt(); // unknown;
|
buffer.getInt(); // unknown;
|
||||||
int flatSeconds = buffer.getInt() / 1000; // ms?
|
flatSeconds = buffer.getInt() / 1000; // ms?
|
||||||
|
|
||||||
addSummaryData("ascentSeconds", ascentSeconds, "seconds");
|
addSummaryData("ascentSeconds", ascentSeconds, "seconds");
|
||||||
addSummaryData("descentSeconds", descentSeconds, "seconds");
|
addSummaryData("descentSeconds", descentSeconds, "seconds");
|
||||||
@ -336,6 +369,10 @@ public class FetchSportsSummaryOperation extends AbstractFetchOperation {
|
|||||||
// summary.setAveragePace(BLETypeConversions.toUnsigned(averagePace);
|
// summary.setAveragePace(BLETypeConversions.toUnsigned(averagePace);
|
||||||
// summary.setAverageStride(BLETypeConversions.toUnsigned(averageStride);
|
// summary.setAverageStride(BLETypeConversions.toUnsigned(averageStride);
|
||||||
|
|
||||||
|
addSummaryData("ascentSeconds", ascentSeconds, "seconds");
|
||||||
|
addSummaryData("descentSeconds", descentSeconds, "seconds");
|
||||||
|
addSummaryData("flatSeconds", flatSeconds, "seconds");
|
||||||
|
|
||||||
addSummaryData("distanceMeters", distanceMeters, "meters");
|
addSummaryData("distanceMeters", distanceMeters, "meters");
|
||||||
addSummaryData("ascentMeters", ascentMeters, "meters");
|
addSummaryData("ascentMeters", ascentMeters, "meters");
|
||||||
addSummaryData("descentMeters", descentMeters, "meters");
|
addSummaryData("descentMeters", descentMeters, "meters");
|
||||||
|
Loading…
Reference in New Issue
Block a user