From c9dcf0652911d9b004874d50052fc9d5dcd825d9 Mon Sep 17 00:00:00 2001 From: Andreas Shimokawa Date: Thu, 17 Dec 2015 23:09:52 +0100 Subject: [PATCH] Pebble: improve debug output - decode apprunstate and systemmessage endpoint messages - prevent error messages by not using appmanager endpoint on firmware 3.x (it is gone) --- .../devices/pebble/PebbleIoThread.java | 3 ++ .../devices/pebble/PebbleProtocol.java | 52 +++++++++++++++++++ 2 files changed, 55 insertions(+) diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/PebbleIoThread.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/PebbleIoThread.java index 4b9b55e6..2a0fc220 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/PebbleIoThread.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/PebbleIoThread.java @@ -426,6 +426,9 @@ public class PebbleIoThread extends GBDeviceIoThread { @Override synchronized public void write(byte[] bytes) { + if (bytes == null) { + return; + } // block writes if app installation in in progress if (mIsConnected && (!mIsInstalling || mInstallState == PebbleAppInstallState.WAIT_SLOT)) { write_real(bytes); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/PebbleProtocol.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/PebbleProtocol.java index 4a6686b7..ae961e4a 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/PebbleProtocol.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/PebbleProtocol.java @@ -161,9 +161,14 @@ public class PebbleProtocol extends GBDeviceProtocol { static final byte SCREENSHOT_TAKE = 0; + static final byte SYSTEMMESSAGE_NEWFIRMWAREAVAILABLE = 0; static final byte SYSTEMMESSAGE_FIRMWARESTART = 1; static final byte SYSTEMMESSAGE_FIRMWARECOMPLETE = 2; static final byte SYSTEMMESSAGE_FIRMWAREFAIL = 3; + static final byte SYSTEMMESSAGE_FIRMWARE_UPTODATE = 4; + static final byte SYSTEMMESSAGE_FIRMWARE_OUTOFDATE = 5; + static final byte SYSTEMMESSAGE_STOPRECONNECTING = 6; + static final byte SYSTEMMESSAGE_STARTRECONNECTING = 7; static final byte PHONEVERSION_REQUEST = 0; static final byte PHONEVERSION_APPVERSION_MAGIC = 2; // increase this if pebble complains @@ -981,6 +986,9 @@ public class PebbleProtocol extends GBDeviceProtocol { @Override public byte[] encodeAppInfoReq() { + if (isFw3x) { + return null; // can't do this on 3.x :( + } return encodeSimpleMessage(ENDPOINT_APPMANAGER, APPMANAGER_GETUUIDS); } @@ -1629,6 +1637,44 @@ public class PebbleProtocol extends GBDeviceProtocol { return null; } + private GBDeviceEvent decodeSystemMessage(ByteBuffer buf) { + buf.get(); // unknown; + byte command = buf.get(); + final String ENDPOINT_NAME = "SYSTEM MESSAGE"; + switch (command) { + case SYSTEMMESSAGE_STOPRECONNECTING: + LOG.info(ENDPOINT_NAME + ": stop reconnecting"); + break; + case SYSTEMMESSAGE_STARTRECONNECTING: + LOG.info(ENDPOINT_NAME + ": start reconnecting"); + break; + default: + LOG.info(ENDPOINT_NAME + ": " + command); + break; + } + return null; + } + + private GBDeviceEvent decodeAppRunState(ByteBuffer buf) { + byte command = buf.get(); + long uuid_high = buf.getLong(); + long uuid_low = buf.getLong(); + UUID uuid = new UUID(uuid_high, uuid_low); + final String ENDPOINT_NAME = "APPRUNSTATE"; + switch (command) { + case APPRUNSTATE_START: + LOG.info(ENDPOINT_NAME + ": started " + uuid); + break; + case APPRUNSTATE_STOP: + LOG.info(ENDPOINT_NAME + ": stopped " + uuid); + break; + default: + LOG.info(ENDPOINT_NAME + ": (cmd:" + command + ")" + uuid); + break; + } + return null; + } + private GBDeviceEventAppManagement decodeAppFetch(ByteBuffer buf) { byte command = buf.get(); if (command == 0x01) { @@ -1911,6 +1957,12 @@ public class PebbleProtocol extends GBDeviceProtocol { case ENDPOINT_APPFETCH: devEvts = new GBDeviceEvent[]{decodeAppFetch(buf)}; break; + case ENDPOINT_SYSTEMMESSAGE: + devEvts = new GBDeviceEvent[]{decodeSystemMessage(buf)}; + break; + case ENDPOINT_APPRUNSTATE: + devEvts = new GBDeviceEvent[]{decodeAppRunState(buf)}; + break; default: break; }