mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-06-22 13:00:17 +02:00
Pebble: corrections to PebbleIoThreads, better logging
This commit is contained in:
parent
7a4330c324
commit
613ff1fc91
|
@ -1,9 +1,5 @@
|
||||||
package nodomain.freeyourgadget.gadgetbridge;
|
package nodomain.freeyourgadget.gadgetbridge;
|
||||||
|
|
||||||
import nodomain.freeyourgadget.gadgetbridge.GBDevice.State;
|
|
||||||
import nodomain.freeyourgadget.gadgetbridge.miband.MiBandSupport;
|
|
||||||
import nodomain.freeyourgadget.gadgetbridge.pebble.PebbleIoThread;
|
|
||||||
import nodomain.freeyourgadget.gadgetbridge.pebble.PebbleSupport;
|
|
||||||
import android.app.NotificationManager;
|
import android.app.NotificationManager;
|
||||||
import android.app.Service;
|
import android.app.Service;
|
||||||
import android.bluetooth.BluetoothAdapter;
|
import android.bluetooth.BluetoothAdapter;
|
||||||
|
@ -23,6 +19,11 @@ import android.support.v4.content.LocalBroadcastManager;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.GBDevice.State;
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.miband.MiBandSupport;
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.pebble.PebbleIoThread;
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.pebble.PebbleSupport;
|
||||||
|
|
||||||
public class BluetoothCommunicationService extends Service {
|
public class BluetoothCommunicationService extends Service {
|
||||||
public static final String ACTION_START
|
public static final String ACTION_START
|
||||||
= "nodomain.freeyourgadget.gadgetbride.bluetoothcommunicationservice.action.start";
|
= "nodomain.freeyourgadget.gadgetbride.bluetoothcommunicationservice.action.start";
|
||||||
|
|
|
@ -1,10 +1,5 @@
|
||||||
package nodomain.freeyourgadget.gadgetbridge;
|
package nodomain.freeyourgadget.gadgetbridge;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import nodomain.freeyourgadget.gadgetbridge.adapter.GBDeviceAdapter;
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.bluetooth.BluetoothAdapter;
|
import android.bluetooth.BluetoothAdapter;
|
||||||
import android.bluetooth.BluetoothDevice;
|
import android.bluetooth.BluetoothDevice;
|
||||||
|
@ -24,6 +19,12 @@ import android.widget.ListView;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.adapter.GBDeviceAdapter;
|
||||||
|
|
||||||
public class ControlCenter extends Activity {
|
public class ControlCenter extends Activity {
|
||||||
|
|
||||||
|
|
||||||
|
@ -114,7 +115,7 @@ public class ControlCenter extends Activity {
|
||||||
/**
|
/**
|
||||||
* Requests information from the {@link BluetoothCommunicationService} about the connection state,
|
* Requests information from the {@link BluetoothCommunicationService} about the connection state,
|
||||||
* firmware info, etc.
|
* firmware info, etc.
|
||||||
*
|
* <p/>
|
||||||
* Note that this method may cause an implicit device connection (for auto-connectable devices).
|
* Note that this method may cause an implicit device connection (for auto-connectable devices).
|
||||||
*/
|
*/
|
||||||
private void requestDeviceInfo() {
|
private void requestDeviceInfo() {
|
||||||
|
|
|
@ -68,13 +68,14 @@ public class GB {
|
||||||
pm.setComponentEnabledSetting(compName, newState, PackageManager.DONT_KILL_APP);
|
pm.setComponentEnabledSetting(compName, newState, PackageManager.DONT_KILL_APP);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public static String hexdump(byte[] buffer, int length) {
|
|
||||||
|
public static String hexdump(byte[] buffer, int offset, int length) {
|
||||||
final char[] hexArray = "0123456789ABCDEF".toCharArray();
|
final char[] hexArray = "0123456789ABCDEF".toCharArray();
|
||||||
char[] hexChars = new char[length * 2];
|
char[] hexChars = new char[length * 2];
|
||||||
for (int j = 0; j < length; j++) {
|
for (int i = 0; i < length; i++) {
|
||||||
int v = buffer[j] & 0xFF;
|
int v = buffer[i + offset] & 0xFF;
|
||||||
hexChars[j * 2] = hexArray[v >>> 4];
|
hexChars[i * 2] = hexArray[v >>> 4];
|
||||||
hexChars[j * 2 + 1] = hexArray[v & 0x0F];
|
hexChars[i * 2 + 1] = hexArray[v & 0x0F];
|
||||||
}
|
}
|
||||||
return new String(hexChars);
|
return new String(hexChars);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,10 @@
|
||||||
package nodomain.freeyourgadget.gadgetbridge.btle;
|
package nodomain.freeyourgadget.gadgetbridge.btle;
|
||||||
|
|
||||||
|
import android.bluetooth.BluetoothGatt;
|
||||||
|
import android.bluetooth.BluetoothGattCharacteristic;
|
||||||
|
import android.bluetooth.BluetoothGattService;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
@ -8,11 +13,6 @@ import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import nodomain.freeyourgadget.gadgetbridge.AbstractDeviceSupport;
|
import nodomain.freeyourgadget.gadgetbridge.AbstractDeviceSupport;
|
||||||
import android.bluetooth.BluetoothGatt;
|
|
||||||
import android.bluetooth.BluetoothGattCharacteristic;
|
|
||||||
import android.bluetooth.BluetoothGattService;
|
|
||||||
import android.bluetooth.BluetoothProfile;
|
|
||||||
import android.util.Log;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see TransactionBuilder
|
* @see TransactionBuilder
|
||||||
|
|
|
@ -1,5 +1,15 @@
|
||||||
package nodomain.freeyourgadget.gadgetbridge.btle;
|
package nodomain.freeyourgadget.gadgetbridge.btle;
|
||||||
|
|
||||||
|
import android.bluetooth.BluetoothAdapter;
|
||||||
|
import android.bluetooth.BluetoothDevice;
|
||||||
|
import android.bluetooth.BluetoothGatt;
|
||||||
|
import android.bluetooth.BluetoothGattCallback;
|
||||||
|
import android.bluetooth.BluetoothGattCharacteristic;
|
||||||
|
import android.bluetooth.BluetoothGattService;
|
||||||
|
import android.bluetooth.BluetoothProfile;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.BlockingQueue;
|
import java.util.concurrent.BlockingQueue;
|
||||||
|
@ -9,15 +19,6 @@ import java.util.concurrent.LinkedBlockingQueue;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.DeviceSupport;
|
import nodomain.freeyourgadget.gadgetbridge.DeviceSupport;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.GBDevice;
|
import nodomain.freeyourgadget.gadgetbridge.GBDevice;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.GBDevice.State;
|
import nodomain.freeyourgadget.gadgetbridge.GBDevice.State;
|
||||||
import android.bluetooth.BluetoothAdapter;
|
|
||||||
import android.bluetooth.BluetoothDevice;
|
|
||||||
import android.bluetooth.BluetoothGatt;
|
|
||||||
import android.bluetooth.BluetoothGattCallback;
|
|
||||||
import android.bluetooth.BluetoothGattCharacteristic;
|
|
||||||
import android.bluetooth.BluetoothGattService;
|
|
||||||
import android.bluetooth.BluetoothProfile;
|
|
||||||
import android.content.Context;
|
|
||||||
import android.util.Log;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* One queue/thread per connectable device.
|
* One queue/thread per connectable device.
|
||||||
|
|
|
@ -5,8 +5,8 @@ import android.bluetooth.BluetoothGattCharacteristic;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.UUID;
|
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
import nodomain.freeyourgadget.gadgetbridge.GBCommand;
|
import nodomain.freeyourgadget.gadgetbridge.GBCommand;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.GBDevice.State;
|
import nodomain.freeyourgadget.gadgetbridge.GBDevice.State;
|
||||||
|
@ -125,29 +125,29 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport {
|
||||||
@Override
|
@Override
|
||||||
public void onSetTime(long ts) {
|
public void onSetTime(long ts) {
|
||||||
// TODO Not sure about the ts value
|
// TODO Not sure about the ts value
|
||||||
Calendar now = Calendar.getInstance();
|
Calendar now = Calendar.getInstance();
|
||||||
byte[] time = new byte[] {
|
byte[] time = new byte[]{
|
||||||
(byte) (now.get(Calendar.YEAR) - 2000),
|
(byte) (now.get(Calendar.YEAR) - 2000),
|
||||||
(byte) now.get(Calendar.MONTH),
|
(byte) now.get(Calendar.MONTH),
|
||||||
(byte) now.get(Calendar.DATE),
|
(byte) now.get(Calendar.DATE),
|
||||||
(byte) now.get(Calendar.HOUR_OF_DAY),
|
(byte) now.get(Calendar.HOUR_OF_DAY),
|
||||||
(byte) now.get(Calendar.MINUTE),
|
(byte) now.get(Calendar.MINUTE),
|
||||||
(byte) now.get(Calendar.SECOND),
|
(byte) now.get(Calendar.SECOND),
|
||||||
(byte) 0x0f,
|
(byte) 0x0f,
|
||||||
(byte) 0x0f,
|
(byte) 0x0f,
|
||||||
(byte) 0x0f,
|
(byte) 0x0f,
|
||||||
(byte) 0x0f,
|
(byte) 0x0f,
|
||||||
(byte) 0x0f,
|
(byte) 0x0f,
|
||||||
(byte) 0x0f
|
(byte) 0x0f
|
||||||
};
|
};
|
||||||
try {
|
try {
|
||||||
TransactionBuilder builder = performInitialized("Set date and time");
|
TransactionBuilder builder = performInitialized("Set date and time");
|
||||||
BluetoothGattCharacteristic characteristic = getCharacteristic(MiBandService.UUID_CHARACTERISTIC_DATE_TIME);
|
BluetoothGattCharacteristic characteristic = getCharacteristic(MiBandService.UUID_CHARACTERISTIC_DATE_TIME);
|
||||||
if (characteristic != null) {
|
if (characteristic != null) {
|
||||||
builder.write(characteristic, time);
|
builder.write(characteristic, time);
|
||||||
} else {
|
} else {
|
||||||
Log.i(TAG, "Unable to set time -- characteristic not available");
|
Log.i(TAG, "Unable to set time -- characteristic not available");
|
||||||
}
|
}
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
Log.e(TAG, "Unable to set time on MI device", ex);
|
Log.e(TAG, "Unable to set time on MI device", ex);
|
||||||
}
|
}
|
||||||
|
|
|
@ -107,7 +107,6 @@ public class PebbleIoThread extends GBDeviceIoThread {
|
||||||
mQuit = !mIsConnected; // quit if not connected
|
mQuit = !mIsConnected; // quit if not connected
|
||||||
|
|
||||||
byte[] buffer = new byte[8192];
|
byte[] buffer = new byte[8192];
|
||||||
int bytes;
|
|
||||||
|
|
||||||
while (!mQuit) {
|
while (!mQuit) {
|
||||||
try {
|
try {
|
||||||
|
@ -147,7 +146,7 @@ public class PebbleIoThread extends GBDeviceIoThread {
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case APP_UPLOAD_CHUNK:
|
case APP_UPLOAD_CHUNK:
|
||||||
bytes = mZis.read(buffer);
|
int bytes = mZis.read(buffer);
|
||||||
|
|
||||||
if (bytes != -1) {
|
if (bytes != -1) {
|
||||||
writeInstallApp(mPebbleProtocol.encodeUploadChunk(mAppInstallToken, buffer, bytes));
|
writeInstallApp(mPebbleProtocol.encodeUploadChunk(mAppInstallToken, buffer, bytes));
|
||||||
|
@ -190,9 +189,10 @@ public class PebbleIoThread extends GBDeviceIoThread {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
bytes = mInStream.read(buffer, 0, 4);
|
int bytes = mInStream.read(buffer, 0, 4);
|
||||||
if (bytes < 4)
|
if (bytes < 4) {
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
ByteBuffer buf = ByteBuffer.wrap(buffer);
|
ByteBuffer buf = ByteBuffer.wrap(buffer);
|
||||||
buf.order(ByteOrder.BIG_ENDIAN);
|
buf.order(ByteOrder.BIG_ENDIAN);
|
||||||
|
@ -207,15 +207,13 @@ public class PebbleIoThread extends GBDeviceIoThread {
|
||||||
}
|
}
|
||||||
|
|
||||||
bytes = mInStream.read(buffer, 4, length);
|
bytes = mInStream.read(buffer, 4, length);
|
||||||
if (bytes < length) {
|
while (bytes < length) {
|
||||||
try {
|
try {
|
||||||
Thread.sleep(100);
|
Thread.sleep(100);
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
//Log.i(TAG, "Read " + bytes + ", expected " + length + " reading remaining " + (length - bytes));
|
bytes += mInStream.read(buffer, bytes + 4, length - bytes);
|
||||||
int bytes_rest = mInStream.read(buffer, 4 + bytes, length - bytes);
|
|
||||||
bytes += bytes_rest;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (length == 1 && endpoint == PebbleProtocol.ENDPOINT_PHONEVERSION) {
|
if (length == 1 && endpoint == PebbleProtocol.ENDPOINT_PHONEVERSION) {
|
||||||
|
@ -230,14 +228,14 @@ public class PebbleIoThread extends GBDeviceIoThread {
|
||||||
write(mPebbleProtocol.encodeSetTime(-1));
|
write(mPebbleProtocol.encodeSetTime(-1));
|
||||||
}
|
}
|
||||||
} else if (endpoint == PebbleProtocol.ENDPOINT_DATALOG) {
|
} else if (endpoint == PebbleProtocol.ENDPOINT_DATALOG) {
|
||||||
Log.i(TAG, "datalog to endpoint " + endpoint + " (" + bytes + " bytes)");
|
Log.i(TAG, "datalog to endpoint " + endpoint + " (" + length + " bytes)");
|
||||||
if (bytes <= 64) {
|
if (length <= 64) {
|
||||||
Log.i(TAG, "hexdump: " + GB.hexdump(buffer, bytes));
|
Log.i(TAG, "hexdump: " + GB.hexdump(buffer, 4, length));
|
||||||
}
|
}
|
||||||
} else {
|
} 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 + " (" + bytes + " bytes)");
|
Log.i(TAG, "unhandled message to endpoint " + endpoint + " (" + length + " bytes)");
|
||||||
} else {
|
} else {
|
||||||
evaluateGBCommandBundle(deviceCmd);
|
evaluateGBCommandBundle(deviceCmd);
|
||||||
}
|
}
|
||||||
|
|
|
@ -402,6 +402,16 @@ public class PebbleProtocol extends GBDeviceProtocol {
|
||||||
return buf.array();
|
return buf.array();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public byte[] encodeDatalog(byte[] buffer) {
|
||||||
|
ByteBuffer buf = ByteBuffer.allocate(LENGTH_PREFIX + buffer.length);
|
||||||
|
buf.order(ByteOrder.BIG_ENDIAN);
|
||||||
|
buf.putShort((short) buffer.length);
|
||||||
|
buf.putShort(ENDPOINT_DATALOG);
|
||||||
|
buf.put(buffer);
|
||||||
|
|
||||||
|
return buf.array();
|
||||||
|
}
|
||||||
|
|
||||||
public GBDeviceCommand decodeResponse(byte[] responseData) {
|
public GBDeviceCommand decodeResponse(byte[] responseData) {
|
||||||
ByteBuffer buf = ByteBuffer.wrap(responseData);
|
ByteBuffer buf = ByteBuffer.wrap(responseData);
|
||||||
buf.order(ByteOrder.BIG_ENDIAN);
|
buf.order(ByteOrder.BIG_ENDIAN);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user