mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-11-28 04:46:51 +01:00
Store raw data in the DB for later interpretation.
This commit is contained in:
parent
b617ba7264
commit
2a2ad20aa3
@ -4,6 +4,7 @@ import org.slf4j.Logger;
|
|||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
|
import java.nio.ByteOrder;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
@ -44,18 +45,13 @@ class DatalogSessionHealthOverlayData extends DatalogSessionPebbleHealth {
|
|||||||
|
|
||||||
int recordCount = length / itemSize;
|
int recordCount = length / itemSize;
|
||||||
OverlayRecord[] overlayRecords = new OverlayRecord[recordCount];
|
OverlayRecord[] overlayRecords = new OverlayRecord[recordCount];
|
||||||
|
byte[] tempRecord = new byte[itemSize];
|
||||||
|
|
||||||
for (int recordIdx = 0; recordIdx < recordCount; recordIdx++) {
|
for (int recordIdx = 0; recordIdx < recordCount; recordIdx++) {
|
||||||
beginOfRecordPosition = initialPosition + recordIdx * itemSize;
|
beginOfRecordPosition = initialPosition + recordIdx * itemSize;
|
||||||
datalogMessage.position(beginOfRecordPosition);//we may not consume all the bytes of a record
|
datalogMessage.position(beginOfRecordPosition);//we may not consume all the bytes of a record
|
||||||
recordVersion = datalogMessage.getShort();
|
datalogMessage.get(tempRecord);
|
||||||
if ((recordVersion != 1) && (recordVersion != 3))
|
overlayRecords[recordIdx] = new OverlayRecord(tempRecord);
|
||||||
return false;//we don't know how to deal with the data TODO: this is not ideal because we will get the same message again and again since we NACK it
|
|
||||||
|
|
||||||
datalogMessage.getShort();//throwaway, unknown
|
|
||||||
recordType = datalogMessage.getShort();
|
|
||||||
|
|
||||||
overlayRecords[recordIdx] = new OverlayRecord(recordType, datalogMessage.getInt(), datalogMessage.getInt(), datalogMessage.getInt());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
store(overlayRecords);
|
store(overlayRecords);
|
||||||
@ -72,7 +68,7 @@ class DatalogSessionHealthOverlayData extends DatalogSessionPebbleHealth {
|
|||||||
|
|
||||||
List<PebbleHealthActivityOverlay> overlayList = new ArrayList<>();
|
List<PebbleHealthActivityOverlay> overlayList = new ArrayList<>();
|
||||||
for (OverlayRecord overlayRecord : overlayRecords) {
|
for (OverlayRecord overlayRecord : overlayRecords) {
|
||||||
overlayList.add(new PebbleHealthActivityOverlay(overlayRecord.timestampStart, overlayRecord.timestampStart + overlayRecord.durationSeconds, overlayRecord.type, deviceId, userId, null));
|
overlayList.add(new PebbleHealthActivityOverlay(overlayRecord.timestampStart, overlayRecord.timestampStart + overlayRecord.durationSeconds, overlayRecord.type, deviceId, userId, overlayRecord.rawData));
|
||||||
}
|
}
|
||||||
overlayDao.insertOrReplaceInTx(overlayList);
|
overlayDao.insertOrReplaceInTx(overlayList);
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
@ -81,16 +77,26 @@ class DatalogSessionHealthOverlayData extends DatalogSessionPebbleHealth {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private class OverlayRecord {
|
private class OverlayRecord {
|
||||||
|
byte[] knownVersions = {1, 3};
|
||||||
|
short version;
|
||||||
int type; //1=sleep, 2=deep sleep
|
int type; //1=sleep, 2=deep sleep
|
||||||
int offsetUTC; //probably
|
int offsetUTC; //probably
|
||||||
int timestampStart;
|
int timestampStart;
|
||||||
int durationSeconds;
|
int durationSeconds;
|
||||||
|
byte[] rawData;
|
||||||
|
|
||||||
public OverlayRecord(int type, int offsetUTC, int timestampStart, int durationSeconds) {
|
public OverlayRecord(byte[] rawData) {
|
||||||
this.type = type;
|
this.rawData = rawData;
|
||||||
this.offsetUTC = offsetUTC;
|
ByteBuffer record = ByteBuffer.wrap(rawData);
|
||||||
this.timestampStart = timestampStart;
|
record.order(ByteOrder.LITTLE_ENDIAN);
|
||||||
this.durationSeconds = durationSeconds;
|
|
||||||
|
this.version = record.getShort();
|
||||||
|
//TODO: check supported versions?
|
||||||
|
record.getShort();//throwaway, unknown
|
||||||
|
this.type = record.getShort();
|
||||||
|
this.offsetUTC = record.getInt();
|
||||||
|
this.timestampStart = record.getInt();
|
||||||
|
this.durationSeconds = record.getInt();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -4,6 +4,7 @@ import org.slf4j.Logger;
|
|||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
|
import java.nio.ByteOrder;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
@ -43,18 +44,14 @@ class DatalogSessionHealthSleep extends DatalogSessionPebbleHealth {
|
|||||||
|
|
||||||
int recordCount = length / itemSize;
|
int recordCount = length / itemSize;
|
||||||
SleepRecord[] sleepRecords = new SleepRecord[recordCount];
|
SleepRecord[] sleepRecords = new SleepRecord[recordCount];
|
||||||
|
byte[] tempRecord = new byte[itemSize];
|
||||||
|
|
||||||
for (int recordIdx = 0; recordIdx < recordCount; recordIdx++) {
|
for (int recordIdx = 0; recordIdx < recordCount; recordIdx++) {
|
||||||
beginOfRecordPosition = initialPosition + recordIdx * itemSize;
|
beginOfRecordPosition = initialPosition + recordIdx * itemSize;
|
||||||
datalogMessage.position(beginOfRecordPosition);//we may not consume all the bytes of a record
|
datalogMessage.position(beginOfRecordPosition);//we may not consume all the bytes of a record
|
||||||
recordVersion = datalogMessage.getShort();
|
datalogMessage.get(tempRecord);
|
||||||
if (recordVersion != 1)
|
|
||||||
return false;//we don't know how to deal with the data TODO: this is not ideal because we will get the same message again and again since we NACK it
|
|
||||||
|
|
||||||
sleepRecords[recordIdx] = new SleepRecord(datalogMessage.getInt(),
|
sleepRecords[recordIdx] = new SleepRecord(tempRecord);
|
||||||
datalogMessage.getInt(),
|
|
||||||
datalogMessage.getInt(),
|
|
||||||
datalogMessage.getInt());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
store(sleepRecords);
|
store(sleepRecords);
|
||||||
@ -71,7 +68,8 @@ class DatalogSessionHealthSleep extends DatalogSessionPebbleHealth {
|
|||||||
|
|
||||||
List<PebbleHealthActivityOverlay> overlayList = new ArrayList<>();
|
List<PebbleHealthActivityOverlay> overlayList = new ArrayList<>();
|
||||||
for (SleepRecord sleepRecord : sleepRecords) {
|
for (SleepRecord sleepRecord : sleepRecords) {
|
||||||
overlayList.add(new PebbleHealthActivityOverlay(sleepRecord.bedTimeStart, sleepRecord.bedTimeEnd, sleepRecord.type, deviceId, userId, null));
|
//TODO: check the firmware version and don't use the sleep record if overlay is available?
|
||||||
|
overlayList.add(new PebbleHealthActivityOverlay(sleepRecord.bedTimeStart, sleepRecord.bedTimeEnd, sleepRecord.type, deviceId, userId, sleepRecord.rawData));
|
||||||
}
|
}
|
||||||
overlayDao.insertOrReplaceInTx(overlayList);
|
overlayDao.insertOrReplaceInTx(overlayList);
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
@ -80,17 +78,27 @@ class DatalogSessionHealthSleep extends DatalogSessionPebbleHealth {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private class SleepRecord {
|
private class SleepRecord {
|
||||||
|
byte[] knownVersions = {1};
|
||||||
|
short version;
|
||||||
int type = 1; //sleep, hardcoded as we don't get other info
|
int type = 1; //sleep, hardcoded as we don't get other info
|
||||||
int offsetUTC; //probably
|
int offsetUTC; //probably
|
||||||
int bedTimeStart;
|
int bedTimeStart;
|
||||||
int bedTimeEnd;
|
int bedTimeEnd;
|
||||||
int deepSleepSeconds;
|
int deepSleepSeconds;
|
||||||
|
byte[] rawData;
|
||||||
|
|
||||||
public SleepRecord(int offsetUTC, int bedTimeStart, int bedTimeEnd, int deepSleepSeconds) {
|
public SleepRecord(byte[] rawData) {
|
||||||
this.offsetUTC = offsetUTC;
|
this.rawData = rawData;
|
||||||
this.bedTimeStart = bedTimeStart;
|
ByteBuffer record = ByteBuffer.wrap(rawData);
|
||||||
this.bedTimeEnd = bedTimeEnd;
|
record.order(ByteOrder.LITTLE_ENDIAN);
|
||||||
this.deepSleepSeconds = deepSleepSeconds;
|
|
||||||
|
|
||||||
|
this.version = record.getShort();
|
||||||
|
//TODO: check supported versions?
|
||||||
|
this.offsetUTC = record.getInt();
|
||||||
|
this.bedTimeStart = record.getInt();
|
||||||
|
this.bedTimeEnd = record.getInt();
|
||||||
|
this.deepSleepSeconds = record.getInt();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,6 +5,7 @@ import org.slf4j.Logger;
|
|||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
|
import java.nio.ByteOrder;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
||||||
@ -59,10 +60,12 @@ public class DatalogSessionHealthSteps extends DatalogSessionPebbleHealth {
|
|||||||
|
|
||||||
beginOfRecordPosition = datalogMessage.position();
|
beginOfRecordPosition = datalogMessage.position();
|
||||||
StepsRecord[] stepsRecords = new StepsRecord[recordNum];
|
StepsRecord[] stepsRecords = new StepsRecord[recordNum];
|
||||||
|
byte[] tempRecord = new byte[recordLength];
|
||||||
|
|
||||||
for (int recordIdx = 0; recordIdx < recordNum; recordIdx++) {
|
for (int recordIdx = 0; recordIdx < recordNum; recordIdx++) {
|
||||||
datalogMessage.position(beginOfRecordPosition + recordIdx * recordLength); //we may not consume all the bytes of a record
|
datalogMessage.position(beginOfRecordPosition + recordIdx * recordLength); //we may not consume all the bytes of a record
|
||||||
stepsRecords[recordIdx] = new StepsRecord(timestamp, datalogMessage.get() & 0xff, datalogMessage.get() & 0xff, datalogMessage.getShort() & 0xffff, datalogMessage.get() & 0xff);
|
datalogMessage.get(tempRecord);
|
||||||
|
stepsRecords[recordIdx] = new StepsRecord(timestamp, recordVersion, tempRecord);
|
||||||
timestamp += 60;
|
timestamp += 60;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -84,7 +87,7 @@ public class DatalogSessionHealthSteps extends DatalogSessionPebbleHealth {
|
|||||||
samples[j] = new PebbleHealthActivitySample(
|
samples[j] = new PebbleHealthActivitySample(
|
||||||
stepsRecord.timestamp,
|
stepsRecord.timestamp,
|
||||||
userId, deviceId,
|
userId, deviceId,
|
||||||
null, // raw data here
|
stepsRecord.rawData,
|
||||||
stepsRecord.intensity,
|
stepsRecord.intensity,
|
||||||
stepsRecord.steps
|
stepsRecord.steps
|
||||||
);
|
);
|
||||||
@ -98,18 +101,28 @@ public class DatalogSessionHealthSteps extends DatalogSessionPebbleHealth {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private class StepsRecord {
|
private class StepsRecord {
|
||||||
|
byte[] knownVersions = {5, 6};
|
||||||
|
short version;
|
||||||
int timestamp;
|
int timestamp;
|
||||||
int steps;
|
int steps;
|
||||||
int orientation;
|
int orientation;
|
||||||
int intensity;
|
int intensity;
|
||||||
int light_intensity;
|
int light_intensity;
|
||||||
|
byte[] rawData;
|
||||||
|
|
||||||
public StepsRecord(int timestamp, int steps, int orientation, int intensity, int light_intensity) {
|
public StepsRecord(int timestamp, short version, byte[] rawData) {
|
||||||
this.timestamp = timestamp;
|
this.timestamp = timestamp;
|
||||||
this.steps = steps;
|
this.rawData = rawData;
|
||||||
this.orientation = orientation;
|
ByteBuffer record = ByteBuffer.wrap(rawData);
|
||||||
this.intensity = intensity;
|
record.order(ByteOrder.LITTLE_ENDIAN);
|
||||||
this.light_intensity = light_intensity;
|
|
||||||
|
this.version = version;
|
||||||
|
//TODO: check supported versions?
|
||||||
|
|
||||||
|
this.steps = record.get() & 0xff;
|
||||||
|
this.orientation = record.get() & 0xff;
|
||||||
|
this.intensity = record.getShort() & 0xffff;
|
||||||
|
this.light_intensity = record.get() & 0xff;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user