1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-12-25 18:15:49 +01:00

HPlus: Enabled decoding of additional fields in day summary message

This commit is contained in:
João Paulo Barraca 2017-01-04 23:24:17 +00:00
parent 9d67394720
commit 91b346b23d

View File

@ -6,33 +6,44 @@ package nodomain.freeyourgadget.gadgetbridge.service.devices.hplus;
import java.util.Calendar;
import java.util.Locale;
class HPlusDataRecordSteps extends HPlusDataRecord{
public int year;
public int month;
public int day;
public int steps;
public int distance;
public int activeTime;
public int maxHeartRate;
public int minHeartRate;
public int calories;
HPlusDataRecordSteps(byte[] data) {
super(data);
int year = (data[10] & 0xFF) * 256 + (data[9] & 0xFF);
int month = data[11] & 0xFF;
int day = data[12] & 0xFF;
year = (data[10] & 0xFF) * 256 + (data[9] & 0xFF);
month = data[11] & 0xFF;
day = data[12] & 0xFF;
//Recover from bug in firmware where year is corrupted
if(year < 1900)
year += 1900;
if (year < 2000 || month > 12 || day > 31) {
throw new IllegalArgumentException("Invalid record date "+year+"-"+month+"-"+day);
}
steps = (data[2] & 0xFF) * 256 + (data[1] & 0xFF);
distance = (data[4] & 0xFF) * 256 + (data[3] & 0xFF);
activeTime = (data[14] & 0xFF) * 256 + (data[13] & 0xFF);
calories = (data[6] & 0xFF) * 256 + (data[5] & 0xFF);
calories += (data[8] & 0xFF) * 256 + (data[7] & 0xFF);
/*
unknown fields
short s12 = (short)(data[5] + data[6] * 256);
short s13 = (short)(data[7] + data[8] * 256);
short s16 = (short)(data[13]) + data[14] * 256);
short s17 = data[15];
short s18 = data[16];
*/
maxHeartRate = data[15] & 0xFF;
minHeartRate = data[16] & 0xFF;
Calendar date = Calendar.getInstance();
date.set(Calendar.YEAR, year);
@ -45,4 +56,8 @@ class HPlusDataRecordSteps extends HPlusDataRecord{
timestamp = (int) (date.getTimeInMillis() / 1000);
}
public String toString(){
return String.format(Locale.US, "%s-%s-%s steps:%d distance:%d minHR:%d maxHR:%d calories:%d activeTime:%d", year, month, day, steps, distance,minHeartRate, maxHeartRate, calories, activeTime);
}
}