From 095c70d469885b8c6426b3a3d816ac710e306d90 Mon Sep 17 00:00:00 2001 From: Andreas Shimokawa Date: Wed, 15 Jul 2015 00:32:13 +0200 Subject: [PATCH] Pebble: preparations for WIP Gadgetbridge Pebble App --- .../pebble/GadgetbridgePblSupport.java | 52 +++++++++++++++++++ .../gadgetbridge/pebble/PebbleProtocol.java | 4 ++ 2 files changed, 56 insertions(+) create mode 100644 app/src/main/java/nodomain/freeyourgadget/gadgetbridge/pebble/GadgetbridgePblSupport.java diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/pebble/GadgetbridgePblSupport.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/pebble/GadgetbridgePblSupport.java new file mode 100644 index 000000000..9720bd4a0 --- /dev/null +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/pebble/GadgetbridgePblSupport.java @@ -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> pairs) { + int timestamp = 0; + for (Pair 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; + } +} diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/pebble/PebbleProtocol.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/pebble/PebbleProtocol.java index af4987044..8737168e0 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/pebble/PebbleProtocol.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/pebble/PebbleProtocol.java @@ -177,6 +177,7 @@ public class PebbleProtocol extends GBDeviceProtocol { private MorpheuzSupport mMorpheuzSupport = new MorpheuzSupport(PebbleProtocol.this); private WeatherNeatSupport mWeatherNeatSupport = new WeatherNeatSupport(PebbleProtocol.this); + private GadgetbridgePblSupport mGadgetbridgePblSupport = new GadgetbridgePblSupport(PebbleProtocol.this); private static byte[] encodeSimpleMessage(short endpoint, byte command) { ByteBuffer buf = ByteBuffer.allocate(LENGTH_PREFIX + LENGTH_SIMPLEMESSAGE); @@ -956,6 +957,9 @@ public class PebbleProtocol extends GBDeviceProtocol { } else if (MorpheuzSupport.uuid.equals(uuid)) { ArrayList> dict = decodeDict(buf); devEvt = mMorpheuzSupport.handleMessage(dict); + } else if (GadgetbridgePblSupport.uuid.equals(uuid)) { + ArrayList> dict = decodeDict(buf); + devEvt = mGadgetbridgePblSupport.handleMessage(dict); } break; case APPLICATIONMESSAGE_ACK: