mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge.git
synced 2025-01-10 17:11:56 +01:00
Pebble: handle DATALOG and PHONEVERSION endpoints directly in protocol
This allows to remove all protocol inspection in PebbleIoThread
This commit is contained in:
parent
7b02548427
commit
33db0bf890
@ -24,7 +24,6 @@ import java.nio.ByteOrder;
|
|||||||
import java.util.zip.ZipInputStream;
|
import java.util.zip.ZipInputStream;
|
||||||
|
|
||||||
import nodomain.freeyourgadget.gadgetbridge.AppManagerActivity;
|
import nodomain.freeyourgadget.gadgetbridge.AppManagerActivity;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.GB;
|
|
||||||
import nodomain.freeyourgadget.gadgetbridge.GBCallControlReceiver;
|
import nodomain.freeyourgadget.gadgetbridge.GBCallControlReceiver;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.GBDevice;
|
import nodomain.freeyourgadget.gadgetbridge.GBDevice;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.GBDeviceIoThread;
|
import nodomain.freeyourgadget.gadgetbridge.GBDeviceIoThread;
|
||||||
@ -137,11 +136,22 @@ public class PebbleIoThread extends GBDeviceIoThread {
|
|||||||
gbDevice.setState(GBDevice.State.CONNECTED);
|
gbDevice.setState(GBDevice.State.CONNECTED);
|
||||||
gbDevice.sendDeviceUpdateIntent(getContext());
|
gbDevice.sendDeviceUpdateIntent(getContext());
|
||||||
|
|
||||||
|
mIsConnected = true;
|
||||||
|
|
||||||
|
SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(getContext());
|
||||||
|
if (sharedPrefs.getBoolean("datetime_synconconnect", true)) {
|
||||||
|
Log.i(TAG, "syncing time");
|
||||||
|
write(mPebbleProtocol.encodeSetTime(-1));
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
gbDevice.setState(GBDevice.State.CONNECTING);
|
||||||
|
gbDevice.sendDeviceUpdateIntent(getContext());
|
||||||
|
|
||||||
mIsConnected = connect(gbDevice.getAddress());
|
mIsConnected = connect(gbDevice.getAddress());
|
||||||
mQuit = !mIsConnected; // quit if not connected
|
mQuit = !mIsConnected; // quit if not connected
|
||||||
|
|
||||||
@ -265,29 +275,12 @@ public class PebbleIoThread extends GBDeviceIoThread {
|
|||||||
bytes += mInStream.read(buffer, bytes + 4, length - bytes);
|
bytes += mInStream.read(buffer, bytes + 4, length - bytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (length == 1 && endpoint == PebbleProtocol.ENDPOINT_PHONEVERSION) {
|
|
||||||
Log.i(TAG, "Pebble asked for Phone/App Version - repLYING!");
|
|
||||||
write(mPebbleProtocol.encodePhoneVersion(PebbleProtocol.PHONEVERSION_REMOTE_OS_ANDROID));
|
|
||||||
write(mPebbleProtocol.encodeFirmwareVersionReq());
|
|
||||||
|
|
||||||
// this does not really belong here, but since the pebble only asks for our version once it should do the job
|
|
||||||
SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(getContext());
|
|
||||||
if (sharedPrefs.getBoolean("datetime_synconconnect", true)) {
|
|
||||||
Log.i(TAG, "syncing time");
|
|
||||||
write(mPebbleProtocol.encodeSetTime(-1));
|
|
||||||
}
|
|
||||||
} else if (endpoint == PebbleProtocol.ENDPOINT_DATALOG) {
|
|
||||||
Log.i(TAG, "datalog to endpoint " + endpoint + " (" + length + " bytes)");
|
|
||||||
Log.i(TAG, "first two bytes: " + GB.hexdump(buffer, 4, 2));
|
|
||||||
write(mPebbleProtocol.encodeDatalog(buffer[5], (byte) 0x85));
|
|
||||||
} else {
|
|
||||||
GBDeviceCommand deviceCmd = mPebbleProtocol.decodeResponse(buffer);
|
GBDeviceCommand deviceCmd = mPebbleProtocol.decodeResponse(buffer);
|
||||||
if (deviceCmd == null) {
|
if (deviceCmd == null) {
|
||||||
Log.i(TAG, "unhandled message to endpoint " + endpoint + " (" + length + " bytes)");
|
Log.i(TAG, "unhandled message to endpoint " + endpoint + " (" + length + " bytes)");
|
||||||
} else {
|
} else {
|
||||||
evaluateGBDeviceCommand(deviceCmd);
|
evaluateGBDeviceCommand(deviceCmd);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
try {
|
try {
|
||||||
Thread.sleep(100);
|
Thread.sleep(100);
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
|
@ -90,6 +90,8 @@ 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 PUTBYTES_INIT = 1;
|
static final byte PUTBYTES_INIT = 1;
|
||||||
static final byte PUTBYTES_SEND = 2;
|
static final byte PUTBYTES_SEND = 2;
|
||||||
static final byte PUTBYTES_COMMIT = 3;
|
static final byte PUTBYTES_COMMIT = 3;
|
||||||
@ -108,6 +110,7 @@ public class PebbleProtocol extends GBDeviceProtocol {
|
|||||||
private final byte SYSTEMMESSAGE_FIRMWARECOMPLETE = 2;
|
private final byte SYSTEMMESSAGE_FIRMWARECOMPLETE = 2;
|
||||||
private final byte SYSTEMMESSAGE_FIRMWAREFAIL = 3;
|
private final byte SYSTEMMESSAGE_FIRMWAREFAIL = 3;
|
||||||
|
|
||||||
|
static final byte PHONEVERSION_REQUEST = 0;
|
||||||
static final byte PHONEVERSION_APPVERSION_MAGIC = 2; // increase this if pebble complains
|
static final byte PHONEVERSION_APPVERSION_MAGIC = 2; // increase this if pebble complains
|
||||||
static final byte PHONEVERSION_APPVERSION_MAJOR = 2;
|
static final byte PHONEVERSION_APPVERSION_MAJOR = 2;
|
||||||
static final byte PHONEVERSION_APPVERSION_MINOR = 3;
|
static final byte PHONEVERSION_APPVERSION_MINOR = 3;
|
||||||
@ -440,7 +443,7 @@ public class PebbleProtocol extends GBDeviceProtocol {
|
|||||||
buf.putShort((short) 4); // length of string
|
buf.putShort((short) 4); // length of string
|
||||||
String temp = "GBT";
|
String temp = "GBT";
|
||||||
buf.put(temp.getBytes());
|
buf.put(temp.getBytes());
|
||||||
buf.put((byte)0x00);
|
buf.put((byte) 0x00);
|
||||||
return buf.array();
|
return buf.array();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -610,6 +613,29 @@ public class PebbleProtocol extends GBDeviceProtocol {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case ENDPOINT_DATALOG:
|
||||||
|
if (pebbleCmd != DATALOG_TIMEOUT) {
|
||||||
|
byte id = buf.get();
|
||||||
|
Log.i(TAG, "DATALOG id " + id + " - sending 0x85 (ACK?)");
|
||||||
|
GBDeviceCommandSendBytes sendBytes = new GBDeviceCommandSendBytes();
|
||||||
|
sendBytes.encodedBytes = encodeDatalog(id, (byte) 0x85);
|
||||||
|
cmd = sendBytes;
|
||||||
|
} else {
|
||||||
|
Log.i(TAG, "DATALOG TIMEOUT - ignoring");
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case ENDPOINT_PHONEVERSION:
|
||||||
|
switch (pebbleCmd) {
|
||||||
|
case PHONEVERSION_REQUEST:
|
||||||
|
Log.i(TAG, "Pebble asked for Phone/App Version - repLYING!");
|
||||||
|
GBDeviceCommandSendBytes sendBytes = new GBDeviceCommandSendBytes();
|
||||||
|
sendBytes.encodedBytes = encodePhoneVersion(PHONEVERSION_REMOTE_OS_ANDROID);
|
||||||
|
cmd = sendBytes;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package nodomain.freeyourgadget.gadgetbridge.pebble;
|
package nodomain.freeyourgadget.gadgetbridge.pebble;
|
||||||
|
|
||||||
import nodomain.freeyourgadget.gadgetbridge.AbstractBTDeviceSupport;
|
import nodomain.freeyourgadget.gadgetbridge.AbstractBTDeviceSupport;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.GBDevice;
|
|
||||||
import nodomain.freeyourgadget.gadgetbridge.GBDeviceIoThread;
|
import nodomain.freeyourgadget.gadgetbridge.GBDeviceIoThread;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.protocol.GBDeviceProtocol;
|
import nodomain.freeyourgadget.gadgetbridge.protocol.GBDeviceProtocol;
|
||||||
|
|
||||||
@ -9,9 +8,6 @@ public class PebbleSupport extends AbstractBTDeviceSupport {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean connect() {
|
public boolean connect() {
|
||||||
// TODO: state and notification handling should move to IO thread
|
|
||||||
getDevice().setState(GBDevice.State.CONNECTING);
|
|
||||||
getDevice().sendDeviceUpdateIntent(getContext());
|
|
||||||
getDeviceIOThread().start();
|
getDeviceIOThread().start();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user