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

Pebble: preparations for WIP Gadgetbridge Pebble App

This commit is contained in:
Andreas Shimokawa 2015-07-15 00:32:13 +02:00
parent d498bd976a
commit 095c70d469
2 changed files with 56 additions and 0 deletions

View File

@ -0,0 +1,52 @@
package nodomain.freeyourgadget.gadgetbridge.pebble;
import android.util.Pair;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.UUID;
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEvent;
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventSendBytes;
public class GadgetbridgePblSupport {
public static final int KEY_TIMESTAMP = 1;
public static final int KEY_SAMPLES = 2;
public static final UUID uuid = UUID.fromString("61476764-7465-7262-6469-656775527a6c");
private final PebbleProtocol mPebbleProtocol;
private static final Logger LOG = LoggerFactory.getLogger(GadgetbridgePblSupport.class);
public GadgetbridgePblSupport(PebbleProtocol pebbleProtocol) {
mPebbleProtocol = pebbleProtocol;
}
public GBDeviceEvent handleMessage(ArrayList<Pair<Integer, Object>> pairs) {
int timestamp = 0;
for (Pair<Integer, Object> pair : pairs) {
switch (pair.first) {
case KEY_TIMESTAMP:
timestamp = (int) pair.second;
LOG.info("got timestamp " + timestamp);
break;
case KEY_SAMPLES:
byte[] samples = (byte[]) pair.second;
LOG.info("got " + samples.length + " samples");
ByteBuffer samplesBuffer = ByteBuffer.wrap(samples);
// TODO: read samples and put into database
break;
default:
LOG.info("unhandled key: " + pair.first);
break;
}
}
GBDeviceEventSendBytes sendBytes = new GBDeviceEventSendBytes();
sendBytes.encodedBytes = mPebbleProtocol.encodeApplicationMessageAck(uuid, mPebbleProtocol.last_id);
return sendBytes;
}
}

View File

@ -177,6 +177,7 @@ public class PebbleProtocol extends GBDeviceProtocol {
private MorpheuzSupport mMorpheuzSupport = new MorpheuzSupport(PebbleProtocol.this); private MorpheuzSupport mMorpheuzSupport = new MorpheuzSupport(PebbleProtocol.this);
private WeatherNeatSupport mWeatherNeatSupport = new WeatherNeatSupport(PebbleProtocol.this); private WeatherNeatSupport mWeatherNeatSupport = new WeatherNeatSupport(PebbleProtocol.this);
private GadgetbridgePblSupport mGadgetbridgePblSupport = new GadgetbridgePblSupport(PebbleProtocol.this);
private static byte[] encodeSimpleMessage(short endpoint, byte command) { private static byte[] encodeSimpleMessage(short endpoint, byte command) {
ByteBuffer buf = ByteBuffer.allocate(LENGTH_PREFIX + LENGTH_SIMPLEMESSAGE); ByteBuffer buf = ByteBuffer.allocate(LENGTH_PREFIX + LENGTH_SIMPLEMESSAGE);
@ -956,6 +957,9 @@ public class PebbleProtocol extends GBDeviceProtocol {
} else if (MorpheuzSupport.uuid.equals(uuid)) { } else if (MorpheuzSupport.uuid.equals(uuid)) {
ArrayList<Pair<Integer, Object>> dict = decodeDict(buf); ArrayList<Pair<Integer, Object>> dict = decodeDict(buf);
devEvt = mMorpheuzSupport.handleMessage(dict); devEvt = mMorpheuzSupport.handleMessage(dict);
} else if (GadgetbridgePblSupport.uuid.equals(uuid)) {
ArrayList<Pair<Integer, Object>> dict = decodeDict(buf);
devEvt = mGadgetbridgePblSupport.handleMessage(dict);
} }
break; break;
case APPLICATIONMESSAGE_ACK: case APPLICATIONMESSAGE_ACK: