Pebble: some cleanups and simplifications for datalogging via PebbleKit
This commit is contained in:
parent
ad9cfae6f9
commit
2dbda6138b
|
@ -13,5 +13,5 @@ public class GBDeviceEventDataLogging extends GBDeviceEvent {
|
|||
public long timestamp;
|
||||
public long tag;
|
||||
public byte pebbleDataType;
|
||||
public Object data;
|
||||
public Object[] data;
|
||||
}
|
||||
|
|
|
@ -6,7 +6,6 @@ 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 {
|
||||
|
@ -37,38 +36,43 @@ class DatalogSession {
|
|||
return taginfo;
|
||||
}
|
||||
|
||||
GBDeviceEvent[] handleMessageForPebbleKit(ByteBuffer buf, int length) {
|
||||
GBDeviceEventDataLogging handleMessageForPebbleKit(ByteBuffer buf, int length) {
|
||||
if (0 != (length % itemSize)) {
|
||||
LOG.warn("invalid length");
|
||||
return null;
|
||||
}
|
||||
int packetCount = length / itemSize;
|
||||
GBDeviceEvent[] gbDeviceEvents = new GBDeviceEvent[packetCount + 1]; // pad for ack
|
||||
|
||||
if (packetCount <= 0) {
|
||||
LOG.warn("invalid number of datalog elements");
|
||||
return null;
|
||||
}
|
||||
|
||||
GBDeviceEventDataLogging dataLogging = new GBDeviceEventDataLogging();
|
||||
dataLogging.command = GBDeviceEventDataLogging.COMMAND_RECEIVE_DATA;
|
||||
dataLogging.appUUID = uuid;
|
||||
dataLogging.timestamp = timestamp & 0xffffffffL;
|
||||
dataLogging.tag = tag;
|
||||
dataLogging.pebbleDataType = itemType;
|
||||
dataLogging.data = new Object[packetCount];
|
||||
|
||||
for (int i = 0; i < packetCount; i++) {
|
||||
GBDeviceEventDataLogging dataLogging = new GBDeviceEventDataLogging();
|
||||
switch (itemType) {
|
||||
case PebbleProtocol.TYPE_BYTEARRAY:
|
||||
byte[] itemData = new byte[itemSize];
|
||||
buf.get(itemData);
|
||||
dataLogging.data = itemData;
|
||||
dataLogging.data[i] = itemData;
|
||||
break;
|
||||
|
||||
case PebbleProtocol.TYPE_UINT:
|
||||
dataLogging.data = buf.getInt() & 0xffffffffL;
|
||||
dataLogging.data[i] = buf.getInt() & 0xffffffffL;
|
||||
break;
|
||||
|
||||
case PebbleProtocol.TYPE_INT:
|
||||
dataLogging.data = buf.getInt();
|
||||
dataLogging.data[i] = buf.getInt();
|
||||
break;
|
||||
}
|
||||
|
||||
dataLogging.command = GBDeviceEventDataLogging.COMMAND_RECEIVE_DATA;
|
||||
dataLogging.appUUID = uuid;
|
||||
dataLogging.timestamp = timestamp & 0xffffffffL;
|
||||
dataLogging.tag = tag;
|
||||
dataLogging.pebbleDataType = itemType;
|
||||
gbDeviceEvents[i] = dataLogging;
|
||||
}
|
||||
return gbDeviceEvents;
|
||||
return dataLogging;
|
||||
}
|
||||
}
|
|
@ -140,30 +140,31 @@ class PebbleKitSupport {
|
|||
switch (dataLogging.command) {
|
||||
case GBDeviceEventDataLogging.COMMAND_RECEIVE_DATA:
|
||||
intent.setAction(PEBBLEKIT_ACTION_DL_RECEIVE_DATA_NEW);
|
||||
intent.putExtra("pbl_data_id", dataLogTransactionId++);
|
||||
intent.putExtra("pbl_data_type", dataLogging.pebbleDataType);
|
||||
switch (dataLogging.pebbleDataType) {
|
||||
case PebbleProtocol.TYPE_BYTEARRAY:
|
||||
intent.putExtra("pbl_data_object", Base64.encodeToString((byte[]) dataLogging.data, Base64.NO_WRAP));
|
||||
break;
|
||||
case PebbleProtocol.TYPE_UINT:
|
||||
intent.putExtra("pbl_data_object", (Long) dataLogging.data);
|
||||
break;
|
||||
case PebbleProtocol.TYPE_INT:
|
||||
intent.putExtra("pbl_data_object", (Integer) dataLogging.data);
|
||||
break;
|
||||
for (Object dataObject : dataLogging.data) {
|
||||
intent.putExtra("pbl_data_id", dataLogTransactionId++);
|
||||
switch (dataLogging.pebbleDataType) {
|
||||
case PebbleProtocol.TYPE_BYTEARRAY:
|
||||
intent.putExtra("pbl_data_object", Base64.encodeToString((byte[]) dataObject, Base64.NO_WRAP));
|
||||
break;
|
||||
case PebbleProtocol.TYPE_UINT:
|
||||
intent.putExtra("pbl_data_object", (Long) dataObject);
|
||||
break;
|
||||
case PebbleProtocol.TYPE_INT:
|
||||
intent.putExtra("pbl_data_object", (Integer) dataObject);
|
||||
break;
|
||||
}
|
||||
LOG.info("broadcasting datalogging to uuid " + dataLogging.appUUID + " tag: " + dataLogging.tag + "transaction id: " + dataLogTransactionId + " type: " + dataLogging.pebbleDataType);
|
||||
mContext.sendBroadcast(intent);
|
||||
}
|
||||
LOG.info("broadcasting datalogging to uuid " + dataLogging.appUUID + " tag: " + dataLogging.tag + "transaction id: " + dataLogTransactionId + " type: " + dataLogging.pebbleDataType);
|
||||
break;
|
||||
case GBDeviceEventDataLogging.COMMAND_FINISH_SESSION:
|
||||
intent.setAction(PEBBLEKIT_ACTION_DL_FINISH_SESSION);
|
||||
LOG.info("broadcasting datalogging finish session to uuid " + dataLogging.appUUID + " tag: " + dataLogging.tag);
|
||||
|
||||
mContext.sendBroadcast(intent);
|
||||
break;
|
||||
default:
|
||||
LOG.warn("invalid datalog command");
|
||||
return;
|
||||
}
|
||||
mContext.sendBroadcast(intent);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2218,7 +2218,7 @@ public class PebbleProtocol extends GBDeviceProtocol {
|
|||
boolean ack = true;
|
||||
byte command = buf.get();
|
||||
byte id = buf.get();
|
||||
GBDeviceEvent[] devEvts = new GBDeviceEvent[1];
|
||||
GBDeviceEventDataLogging devEvtDataLogging = null;
|
||||
switch (command) {
|
||||
case DATALOG_TIMEOUT:
|
||||
LOG.info("DATALOG TIMEOUT. id=" + (id & 0xff) + " - ignoring");
|
||||
|
@ -2232,7 +2232,10 @@ 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) {
|
||||
devEvts = datalogSession.handleMessageForPebbleKit(buf, length - 10);
|
||||
devEvtDataLogging = datalogSession.handleMessageForPebbleKit(buf, length - 10);
|
||||
if (devEvtDataLogging == null) {
|
||||
ack = false;
|
||||
}
|
||||
} else {
|
||||
ack = datalogSession.handleMessage(buf, length - 10);
|
||||
}
|
||||
|
@ -2269,7 +2272,7 @@ public class PebbleProtocol extends GBDeviceProtocol {
|
|||
dataLogging.command = GBDeviceEventDataLogging.COMMAND_FINISH_SESSION;
|
||||
dataLogging.appUUID = datalogSession.uuid;
|
||||
dataLogging.tag = datalogSession.tag;
|
||||
devEvts = new GBDeviceEvent[]{dataLogging, null};
|
||||
devEvtDataLogging = dataLogging;
|
||||
}
|
||||
mDatalogSessions.remove(id);
|
||||
}
|
||||
|
@ -2287,8 +2290,7 @@ public class PebbleProtocol extends GBDeviceProtocol {
|
|||
sendBytes.encodedBytes = encodeDatalog(id, DATALOG_NACK);
|
||||
}
|
||||
// append ack/nack
|
||||
devEvts[devEvts.length - 1] = sendBytes;
|
||||
return devEvts;
|
||||
return new GBDeviceEvent[]{devEvtDataLogging, sendBytes};
|
||||
}
|
||||
|
||||
private GBDeviceEvent decodeAppReorder(ByteBuffer buf) {
|
||||
|
|
Loading…
Reference in New Issue