Allow Datalog handlers to return GBDeviceEvent[]
This commit is contained in:
parent
07272e5a68
commit
b25bc66485
|
@ -22,6 +22,7 @@ import org.slf4j.LoggerFactory;
|
|||
import java.nio.ByteBuffer;
|
||||
import java.util.UUID;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEvent;
|
||||
import nodomain.freeyourgadget.gadgetbridge.deviceevents.pebble.GBDeviceEventDataLogging;
|
||||
|
||||
class DatalogSession {
|
||||
|
@ -44,15 +45,15 @@ class DatalogSession {
|
|||
this.itemSize = itemSize;
|
||||
}
|
||||
|
||||
boolean handleMessage(ByteBuffer buf, int length) {
|
||||
return true;
|
||||
GBDeviceEvent[] handleMessage(ByteBuffer buf, int length) {
|
||||
return new GBDeviceEvent[]{null};
|
||||
}
|
||||
|
||||
String getTaginfo() {
|
||||
return taginfo;
|
||||
}
|
||||
|
||||
GBDeviceEventDataLogging handleMessageForPebbleKit(ByteBuffer buf, int length) {
|
||||
GBDeviceEvent[] handleMessageForPebbleKit(ByteBuffer buf, int length) {
|
||||
if (0 != (length % itemSize)) {
|
||||
LOG.warn("invalid length");
|
||||
return null;
|
||||
|
@ -89,6 +90,6 @@ class DatalogSession {
|
|||
break;
|
||||
}
|
||||
}
|
||||
return dataLogging;
|
||||
return new GBDeviceEvent[]{dataLogging, null};
|
||||
}
|
||||
}
|
|
@ -22,6 +22,7 @@ import org.slf4j.LoggerFactory;
|
|||
import java.nio.ByteBuffer;
|
||||
import java.util.UUID;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEvent;
|
||||
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
||||
import nodomain.freeyourgadget.gadgetbridge.util.GB;
|
||||
|
||||
|
@ -35,9 +36,9 @@ class DatalogSessionHealthHR extends DatalogSessionPebbleHealth {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean handleMessage(ByteBuffer datalogMessage, int length) {
|
||||
public GBDeviceEvent[] handleMessage(ByteBuffer datalogMessage, int length) {
|
||||
LOG.info("DATALOG " + taginfo + GB.hexdump(datalogMessage.array(), datalogMessage.position(), length));
|
||||
|
||||
return isPebbleHealthEnabled();
|
||||
return isPebbleHealthEnabled() ? new GBDeviceEvent[]{null} : null;
|
||||
}
|
||||
}
|
|
@ -29,6 +29,7 @@ import java.util.UUID;
|
|||
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
||||
import nodomain.freeyourgadget.gadgetbridge.database.DBHandler;
|
||||
import nodomain.freeyourgadget.gadgetbridge.database.DBHelper;
|
||||
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEvent;
|
||||
import nodomain.freeyourgadget.gadgetbridge.entities.DaoSession;
|
||||
import nodomain.freeyourgadget.gadgetbridge.entities.PebbleHealthActivityOverlay;
|
||||
import nodomain.freeyourgadget.gadgetbridge.entities.PebbleHealthActivityOverlayDao;
|
||||
|
@ -45,11 +46,11 @@ class DatalogSessionHealthOverlayData extends DatalogSessionPebbleHealth {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean handleMessage(ByteBuffer datalogMessage, int length) {
|
||||
public GBDeviceEvent[] handleMessage(ByteBuffer datalogMessage, int length) {
|
||||
LOG.info("DATALOG " + taginfo + GB.hexdump(datalogMessage.array(), datalogMessage.position(), length));
|
||||
|
||||
if (!isPebbleHealthEnabled()) {
|
||||
return false;
|
||||
return null;
|
||||
}
|
||||
|
||||
int initialPosition = datalogMessage.position();
|
||||
|
@ -58,7 +59,7 @@ class DatalogSessionHealthOverlayData extends DatalogSessionPebbleHealth {
|
|||
short recordType; //probably: 1=sleep, 2=deep sleep, 5=??run??ignored for now
|
||||
|
||||
if (0 != (length % itemSize))
|
||||
return false;//malformed message?
|
||||
return null;//malformed message?
|
||||
|
||||
int recordCount = length / itemSize;
|
||||
OverlayRecord[] overlayRecords = new OverlayRecord[recordCount];
|
||||
|
@ -72,7 +73,7 @@ class DatalogSessionHealthOverlayData extends DatalogSessionPebbleHealth {
|
|||
}
|
||||
|
||||
store(overlayRecords);
|
||||
return true;
|
||||
return new GBDeviceEvent[]{null};
|
||||
}
|
||||
|
||||
private void store(OverlayRecord[] overlayRecords) {
|
||||
|
|
|
@ -29,6 +29,7 @@ import java.util.UUID;
|
|||
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
||||
import nodomain.freeyourgadget.gadgetbridge.database.DBHandler;
|
||||
import nodomain.freeyourgadget.gadgetbridge.database.DBHelper;
|
||||
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEvent;
|
||||
import nodomain.freeyourgadget.gadgetbridge.entities.DaoSession;
|
||||
import nodomain.freeyourgadget.gadgetbridge.entities.PebbleHealthActivityOverlay;
|
||||
import nodomain.freeyourgadget.gadgetbridge.entities.PebbleHealthActivityOverlayDao;
|
||||
|
@ -45,11 +46,11 @@ class DatalogSessionHealthSleep extends DatalogSessionPebbleHealth {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean handleMessage(ByteBuffer datalogMessage, int length) {
|
||||
public GBDeviceEvent[] handleMessage(ByteBuffer datalogMessage, int length) {
|
||||
LOG.info("DATALOG " + taginfo + GB.hexdump(datalogMessage.array(), datalogMessage.position(), length));
|
||||
|
||||
if (!isPebbleHealthEnabled()) {
|
||||
return false;
|
||||
return null;
|
||||
}
|
||||
|
||||
int initialPosition = datalogMessage.position();
|
||||
|
@ -57,7 +58,7 @@ class DatalogSessionHealthSleep extends DatalogSessionPebbleHealth {
|
|||
short recordVersion; //probably
|
||||
|
||||
if (0 != (length % itemSize))
|
||||
return false;//malformed message?
|
||||
return null;//malformed message?
|
||||
|
||||
int recordCount = length / itemSize;
|
||||
SleepRecord[] sleepRecords = new SleepRecord[recordCount];
|
||||
|
@ -72,7 +73,7 @@ class DatalogSessionHealthSleep extends DatalogSessionPebbleHealth {
|
|||
}
|
||||
|
||||
store(sleepRecords);
|
||||
return true;
|
||||
return new GBDeviceEvent[]{null};
|
||||
}
|
||||
|
||||
private void store(SleepRecord[] sleepRecords) {
|
||||
|
|
|
@ -28,6 +28,7 @@ import java.util.UUID;
|
|||
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
||||
import nodomain.freeyourgadget.gadgetbridge.database.DBHandler;
|
||||
import nodomain.freeyourgadget.gadgetbridge.database.DBHelper;
|
||||
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEvent;
|
||||
import nodomain.freeyourgadget.gadgetbridge.devices.pebble.PebbleHealthSampleProvider;
|
||||
import nodomain.freeyourgadget.gadgetbridge.entities.PebbleHealthActivitySample;
|
||||
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
||||
|
@ -43,11 +44,11 @@ class DatalogSessionHealthSteps extends DatalogSessionPebbleHealth {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean handleMessage(ByteBuffer datalogMessage, int length) {
|
||||
public GBDeviceEvent[] handleMessage(ByteBuffer datalogMessage, int length) {
|
||||
LOG.info("DATALOG " + taginfo + GB.hexdump(datalogMessage.array(), datalogMessage.position(), length));
|
||||
|
||||
if (!isPebbleHealthEnabled()) {
|
||||
return false;
|
||||
return null;
|
||||
}
|
||||
|
||||
int timestamp;
|
||||
|
@ -57,7 +58,7 @@ class DatalogSessionHealthSteps extends DatalogSessionPebbleHealth {
|
|||
|
||||
int initialPosition = datalogMessage.position();
|
||||
if (0 != (length % itemSize))
|
||||
return false;//malformed message?
|
||||
return null;//malformed message?
|
||||
|
||||
int packetCount = length / itemSize;
|
||||
|
||||
|
@ -68,7 +69,7 @@ class DatalogSessionHealthSteps extends DatalogSessionPebbleHealth {
|
|||
recordVersion = datalogMessage.getShort();
|
||||
|
||||
if ((recordVersion != 5) && (recordVersion != 6) && (recordVersion != 7) && (recordVersion != 12) && (recordVersion != 13))
|
||||
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
|
||||
return null; //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
|
||||
|
||||
timestamp = datalogMessage.getInt();
|
||||
datalogMessage.get(); //unknown, throw away
|
||||
|
@ -88,7 +89,7 @@ class DatalogSessionHealthSteps extends DatalogSessionPebbleHealth {
|
|||
|
||||
store(stepsRecords);
|
||||
}
|
||||
return true;//ACK by default
|
||||
return new GBDeviceEvent[]{null};//ACK by default
|
||||
}
|
||||
|
||||
private void store(StepsRecord[] stepsRecords) {
|
||||
|
|
|
@ -2232,10 +2232,9 @@ public class PebbleProtocol extends GBDeviceProtocol {
|
|||
}
|
||||
|
||||
private GBDeviceEvent[] decodeDatalog(ByteBuffer buf, short length) {
|
||||
boolean ack = true;
|
||||
byte command = buf.get();
|
||||
byte id = buf.get();
|
||||
GBDeviceEventDataLogging devEvtDataLogging = null;
|
||||
GBDeviceEvent[] devEvtsDataLogging = null;
|
||||
switch (command) {
|
||||
case DATALOG_TIMEOUT:
|
||||
LOG.info("DATALOG TIMEOUT. id=" + (id & 0xff) + " - ignoring");
|
||||
|
@ -2249,12 +2248,9 @@ public class PebbleProtocol extends GBDeviceProtocol {
|
|||
if (datalogSession != null) {
|
||||
LOG.info("DATALOG UUID=" + datalogSession.uuid + ", tag=" + datalogSession.tag + datalogSession.getTaginfo() + ", itemSize=" + datalogSession.itemSize + ", itemType=" + datalogSession.itemType);
|
||||
if (!datalogSession.uuid.equals(UUID_ZERO) && datalogSession.getClass().equals(DatalogSession.class) && mEnablePebbleKit) {
|
||||
devEvtDataLogging = datalogSession.handleMessageForPebbleKit(buf, length - 10);
|
||||
if (devEvtDataLogging == null) {
|
||||
ack = false;
|
||||
}
|
||||
devEvtsDataLogging = datalogSession.handleMessageForPebbleKit(buf, length - 10);
|
||||
} else {
|
||||
ack = datalogSession.handleMessage(buf, length - 10);
|
||||
devEvtsDataLogging = datalogSession.handleMessage(buf, length - 10);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
@ -2289,7 +2285,7 @@ public class PebbleProtocol extends GBDeviceProtocol {
|
|||
dataLogging.command = GBDeviceEventDataLogging.COMMAND_FINISH_SESSION;
|
||||
dataLogging.appUUID = datalogSession.uuid;
|
||||
dataLogging.tag = datalogSession.tag;
|
||||
devEvtDataLogging = dataLogging;
|
||||
devEvtsDataLogging = new GBDeviceEvent[]{dataLogging, null};
|
||||
}
|
||||
mDatalogSessions.remove(id);
|
||||
}
|
||||
|
@ -2299,15 +2295,18 @@ public class PebbleProtocol extends GBDeviceProtocol {
|
|||
break;
|
||||
}
|
||||
GBDeviceEventSendBytes sendBytes = new GBDeviceEventSendBytes();
|
||||
if (ack) {
|
||||
|
||||
if (devEvtsDataLogging != null) {
|
||||
// append ack
|
||||
LOG.info("sending ACK (0x85)");
|
||||
sendBytes.encodedBytes = encodeDatalog(id, DATALOG_ACK);
|
||||
devEvtsDataLogging[devEvtsDataLogging.length - 1] = sendBytes;
|
||||
} else {
|
||||
LOG.info("sending NACK (0x86)");
|
||||
sendBytes.encodedBytes = encodeDatalog(id, DATALOG_NACK);
|
||||
devEvtsDataLogging = new GBDeviceEvent[]{sendBytes};
|
||||
}
|
||||
// append ack/nack
|
||||
return new GBDeviceEvent[]{devEvtDataLogging, sendBytes};
|
||||
return devEvtsDataLogging;
|
||||
}
|
||||
|
||||
private GBDeviceEvent decodeAppReorder(ByteBuffer buf) {
|
||||
|
|
Loading…
Reference in New Issue