Pebble: answer pings from the watch
This commit is contained in:
parent
27f88e484d
commit
d983d7a5c4
|
@ -13,8 +13,6 @@ import java.util.Random;
|
||||||
import java.util.SimpleTimeZone;
|
import java.util.SimpleTimeZone;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import nodomain.freeyourgadget.gadgetbridge.model.ServiceCommand;
|
|
||||||
import nodomain.freeyourgadget.gadgetbridge.impl.GBDeviceApp;
|
|
||||||
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEvent;
|
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEvent;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventAppInfo;
|
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventAppInfo;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventAppManagementResult;
|
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventAppManagementResult;
|
||||||
|
@ -24,6 +22,8 @@ import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventMusicContr
|
||||||
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventScreenshot;
|
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventScreenshot;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventSendBytes;
|
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventSendBytes;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventVersionInfo;
|
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventVersionInfo;
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.impl.GBDeviceApp;
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.model.ServiceCommand;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.service.bt.GBDeviceProtocol;
|
import nodomain.freeyourgadget.gadgetbridge.service.bt.GBDeviceProtocol;
|
||||||
|
|
||||||
public class PebbleProtocol extends GBDeviceProtocol {
|
public class PebbleProtocol extends GBDeviceProtocol {
|
||||||
|
@ -99,7 +99,13 @@ public class PebbleProtocol extends GBDeviceProtocol {
|
||||||
static final byte APPLICATIONMESSAGE_ACK = (byte) 0xff;
|
static final byte APPLICATIONMESSAGE_ACK = (byte) 0xff;
|
||||||
static final byte APPLICATIONMESSAGE_NACK = (byte) 0x7f;
|
static final byte APPLICATIONMESSAGE_NACK = (byte) 0x7f;
|
||||||
|
|
||||||
static final byte DATALOG_TIMEOUT = 7;
|
static final byte DATALOG_CLOSE = (byte) 0x03;
|
||||||
|
static final byte DATALOG_TIMEOUT = 0x07;
|
||||||
|
static final byte DATALOG_ACK = (byte) 0x85;
|
||||||
|
static final byte DATALOG_NACK = (byte) 0x86;
|
||||||
|
|
||||||
|
static final byte PING_PING = 0;
|
||||||
|
static final byte PING_PONG = 1;
|
||||||
|
|
||||||
static final byte PUTBYTES_INIT = 1;
|
static final byte PUTBYTES_INIT = 1;
|
||||||
static final byte PUTBYTES_SEND = 2;
|
static final byte PUTBYTES_SEND = 2;
|
||||||
|
@ -154,6 +160,7 @@ public class PebbleProtocol extends GBDeviceProtocol {
|
||||||
static final byte TYPE_INT32 = 3;
|
static final byte TYPE_INT32 = 3;
|
||||||
|
|
||||||
static final short LENGTH_PREFIX = 4;
|
static final short LENGTH_PREFIX = 4;
|
||||||
|
static final short LENGTH_PING = 5;
|
||||||
static final short LENGTH_SIMPLEMESSAGE = 1;
|
static final short LENGTH_SIMPLEMESSAGE = 1;
|
||||||
static final short LENGTH_SETTIME = 5;
|
static final short LENGTH_SETTIME = 5;
|
||||||
static final short LENGTH_REMOVEAPP = 17;
|
static final short LENGTH_REMOVEAPP = 17;
|
||||||
|
@ -697,6 +704,16 @@ public class PebbleProtocol extends GBDeviceProtocol {
|
||||||
return buf.array();
|
return buf.array();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static byte[] encodePing(byte command, int cookie) {
|
||||||
|
ByteBuffer buf = ByteBuffer.allocate(LENGTH_PREFIX + LENGTH_PING);
|
||||||
|
buf.order(ByteOrder.BIG_ENDIAN);
|
||||||
|
buf.putShort(LENGTH_PING);
|
||||||
|
buf.putShort(ENDPOINT_PING);
|
||||||
|
buf.put(command);
|
||||||
|
buf.putInt(cookie);
|
||||||
|
|
||||||
|
return buf.array();
|
||||||
|
}
|
||||||
|
|
||||||
private ArrayList<Pair<Integer, Object>> decodeDict(ByteBuffer buf) {
|
private ArrayList<Pair<Integer, Object>> decodeDict(ByteBuffer buf) {
|
||||||
ArrayList<Pair<Integer, Object>> dict = new ArrayList<Pair<Integer, Object>>();
|
ArrayList<Pair<Integer, Object>> dict = new ArrayList<Pair<Integer, Object>>();
|
||||||
|
@ -775,7 +792,7 @@ public class PebbleProtocol extends GBDeviceProtocol {
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
private GBDeviceEvent decodeResponseScreenshot(ByteBuffer buf, int length) {
|
private GBDeviceEventScreenshot decodeResponseScreenshot(ByteBuffer buf, int length) {
|
||||||
if (mDevEventScreenshot == null) {
|
if (mDevEventScreenshot == null) {
|
||||||
byte result = buf.get();
|
byte result = buf.get();
|
||||||
mDevEventScreenshot = new GBDeviceEventScreenshot();
|
mDevEventScreenshot = new GBDeviceEventScreenshot();
|
||||||
|
@ -820,7 +837,7 @@ public class PebbleProtocol extends GBDeviceProtocol {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private GBDeviceEvent decodeResponseNotificationAction(ByteBuffer buf, int length) {
|
private GBDeviceEventDismissNotification decodeResponseNotificationAction(ByteBuffer buf, int length) {
|
||||||
buf.order(ByteOrder.LITTLE_ENDIAN);
|
buf.order(ByteOrder.LITTLE_ENDIAN);
|
||||||
|
|
||||||
byte command = buf.get();
|
byte command = buf.get();
|
||||||
|
@ -842,6 +859,18 @@ public class PebbleProtocol extends GBDeviceProtocol {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private GBDeviceEventSendBytes decodeResponsePing(ByteBuffer buf, int length) {
|
||||||
|
byte command = buf.get();
|
||||||
|
if (command == PING_PING) {
|
||||||
|
int cookie = buf.getInt();
|
||||||
|
LOG.info("Received PING - will reply");
|
||||||
|
GBDeviceEventSendBytes sendBytes = new GBDeviceEventSendBytes();
|
||||||
|
sendBytes.encodedBytes = encodePing(PING_PONG, cookie);
|
||||||
|
return sendBytes;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public GBDeviceEvent decodeResponse(byte[] responseData) {
|
public GBDeviceEvent decodeResponse(byte[] responseData) {
|
||||||
ByteBuffer buf = ByteBuffer.wrap(responseData);
|
ByteBuffer buf = ByteBuffer.wrap(responseData);
|
||||||
|
@ -1042,9 +1071,9 @@ public class PebbleProtocol extends GBDeviceProtocol {
|
||||||
pebbleCmd = buf.get();
|
pebbleCmd = buf.get();
|
||||||
if (pebbleCmd != DATALOG_TIMEOUT) {
|
if (pebbleCmd != DATALOG_TIMEOUT) {
|
||||||
byte id = buf.get();
|
byte id = buf.get();
|
||||||
LOG.info("DATALOG id " + id + " - sending 0x85 (ACK?)");
|
LOG.info("DATALOG id " + id + " - sending ACK (0x85)");
|
||||||
GBDeviceEventSendBytes sendBytes = new GBDeviceEventSendBytes();
|
GBDeviceEventSendBytes sendBytes = new GBDeviceEventSendBytes();
|
||||||
sendBytes.encodedBytes = encodeDatalog(id, (byte) 0x85);
|
sendBytes.encodedBytes = encodeDatalog(id, DATALOG_ACK);
|
||||||
devEvt = sendBytes;
|
devEvt = sendBytes;
|
||||||
} else {
|
} else {
|
||||||
LOG.info("DATALOG TIMEOUT - ignoring");
|
LOG.info("DATALOG TIMEOUT - ignoring");
|
||||||
|
@ -1070,6 +1099,9 @@ public class PebbleProtocol extends GBDeviceProtocol {
|
||||||
case ENDPOINT_NOTIFICATIONACTION:
|
case ENDPOINT_NOTIFICATIONACTION:
|
||||||
devEvt = decodeResponseNotificationAction(buf, length);
|
devEvt = decodeResponseNotificationAction(buf, length);
|
||||||
break;
|
break;
|
||||||
|
case ENDPOINT_PING:
|
||||||
|
devEvt = decodeResponsePing(buf, length);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue