2019-02-13 20:43:30 +01:00
|
|
|
/* Copyright (C) 2017-2019 João Paulo Barraca
|
2017-03-10 14:53:19 +01:00
|
|
|
|
|
|
|
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/>. */
|
2017-01-02 01:58:37 +01:00
|
|
|
package nodomain.freeyourgadget.gadgetbridge.service.devices.hplus;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @author João Paulo Barraca <jpbarraca@gmail.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.Calendar;
|
2017-01-05 00:41:35 +01:00
|
|
|
import java.util.GregorianCalendar;
|
2017-01-05 00:24:17 +01:00
|
|
|
import java.util.Locale;
|
2017-01-02 01:58:37 +01:00
|
|
|
|
|
|
|
|
2017-01-05 11:33:37 +01:00
|
|
|
class HPlusDataRecordDaySummary extends HPlusDataRecord{
|
2017-01-05 01:03:54 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Year of the record reported by the device
|
|
|
|
* Sometimes the device will report a low number (e.g, 116) which will be "corrected"
|
|
|
|
* by adding 1900
|
|
|
|
*/
|
2017-01-05 00:24:17 +01:00
|
|
|
public int year;
|
2017-01-05 01:03:54 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Month of the record reported by the device from 1 to 12
|
|
|
|
*/
|
2017-01-05 00:24:17 +01:00
|
|
|
public int month;
|
2017-01-05 01:03:54 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Day of the record reported by the device
|
|
|
|
*/
|
2017-01-05 00:24:17 +01:00
|
|
|
public int day;
|
|
|
|
|
2017-01-05 01:03:54 +01:00
|
|
|
/**
|
|
|
|
* Number of steps accumulated in the day reported
|
|
|
|
*/
|
2017-01-04 02:46:24 +01:00
|
|
|
public int steps;
|
2017-01-05 01:03:54 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Distance in meters accumulated in the day reported
|
|
|
|
*/
|
2017-01-04 02:46:24 +01:00
|
|
|
public int distance;
|
2017-01-02 01:58:37 +01:00
|
|
|
|
2017-01-05 01:03:54 +01:00
|
|
|
/**
|
|
|
|
* Amount of time active in the day (Units are To Be Determined)
|
|
|
|
*/
|
2017-01-05 00:24:17 +01:00
|
|
|
public int activeTime;
|
2017-01-05 01:03:54 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Max Heart Rate recorded in Beats Per Minute
|
|
|
|
*/
|
2017-01-05 00:24:17 +01:00
|
|
|
public int maxHeartRate;
|
2017-01-05 01:03:54 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Min Heart Rate recorded in Beats Per Minute
|
|
|
|
*/
|
2017-01-05 00:24:17 +01:00
|
|
|
public int minHeartRate;
|
2017-01-05 01:03:54 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Amount of estimated calories consumed during the day in KCalories
|
|
|
|
*/
|
2017-01-05 00:24:17 +01:00
|
|
|
public int calories;
|
|
|
|
|
2017-01-05 11:33:37 +01:00
|
|
|
HPlusDataRecordDaySummary(byte[] data) {
|
2017-01-10 14:08:45 +01:00
|
|
|
super(data, TYPE_DAY_SUMMARY);
|
2017-01-02 01:58:37 +01:00
|
|
|
|
2017-01-05 00:24:17 +01:00
|
|
|
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
|
2017-01-05 01:03:54 +01:00
|
|
|
//data[10] will be set to 0, effectively offsetting values by minus 1900 years
|
2017-01-05 00:24:17 +01:00
|
|
|
if(year < 1900)
|
|
|
|
year += 1900;
|
2017-01-02 01:58:37 +01:00
|
|
|
|
|
|
|
if (year < 2000 || month > 12 || day > 31) {
|
|
|
|
throw new IllegalArgumentException("Invalid record date "+year+"-"+month+"-"+day);
|
|
|
|
}
|
|
|
|
steps = (data[2] & 0xFF) * 256 + (data[1] & 0xFF);
|
2017-01-10 14:08:45 +01:00
|
|
|
distance = ((data[4] & 0xFF) * 256 + (data[3] & 0xFF)) * 10;
|
2017-01-05 00:24:17 +01:00
|
|
|
activeTime = (data[14] & 0xFF) * 256 + (data[13] & 0xFF);
|
|
|
|
calories = (data[6] & 0xFF) * 256 + (data[5] & 0xFF);
|
|
|
|
calories += (data[8] & 0xFF) * 256 + (data[7] & 0xFF);
|
2017-01-02 01:58:37 +01:00
|
|
|
|
2017-01-05 00:24:17 +01:00
|
|
|
maxHeartRate = data[15] & 0xFF;
|
|
|
|
minHeartRate = data[16] & 0xFF;
|
2017-01-02 01:58:37 +01:00
|
|
|
|
2017-01-05 00:41:35 +01:00
|
|
|
Calendar date = GregorianCalendar.getInstance();
|
2017-01-02 01:58:37 +01:00
|
|
|
date.set(Calendar.YEAR, year);
|
|
|
|
date.set(Calendar.MONTH, month - 1);
|
|
|
|
date.set(Calendar.DAY_OF_MONTH, day);
|
2017-01-04 02:46:24 +01:00
|
|
|
date.set(Calendar.HOUR_OF_DAY, 23);
|
2017-01-02 01:58:37 +01:00
|
|
|
date.set(Calendar.MINUTE, 59);
|
|
|
|
date.set(Calendar.SECOND, 59);
|
|
|
|
date.set(Calendar.MILLISECOND, 999);
|
|
|
|
|
|
|
|
timestamp = (int) (date.getTimeInMillis() / 1000);
|
|
|
|
}
|
2017-01-05 00:24:17 +01:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
2017-01-02 01:58:37 +01:00
|
|
|
}
|