mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge.git
synced 2025-01-11 17:41:57 +01:00
still don't know what is goind on with uploading files...
This commit is contained in:
parent
1318b58ad2
commit
016ae8be13
@ -40,6 +40,7 @@ import nodomain.freeyourgadget.gadgetbridge.model.BatteryState;
|
|||||||
import nodomain.freeyourgadget.gadgetbridge.model.GenericItem;
|
import nodomain.freeyourgadget.gadgetbridge.model.GenericItem;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.model.NotificationSpec;
|
import nodomain.freeyourgadget.gadgetbridge.model.NotificationSpec;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.model.RecordedDataTypes;
|
import nodomain.freeyourgadget.gadgetbridge.model.RecordedDataTypes;
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.service.btle.GattCallback;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder;
|
import nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.service.btle.actions.SetDeviceStateAction;
|
import nodomain.freeyourgadget.gadgetbridge.service.btle.actions.SetDeviceStateAction;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.adapter.WatchAdapter;
|
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.adapter.WatchAdapter;
|
||||||
@ -73,6 +74,7 @@ public class QHybridSupport extends QHybridBaseSupport {
|
|||||||
public static final String ITEM_EXTENDED_VIBRATION_SUPPORT = "EXTENDED_VIBRATION";
|
public static final String ITEM_EXTENDED_VIBRATION_SUPPORT = "EXTENDED_VIBRATION";
|
||||||
public static final String ITEM_HAS_ACTIVITY_HAND = "HAS_ACTIVITY_HAND";
|
public static final String ITEM_HAS_ACTIVITY_HAND = "HAS_ACTIVITY_HAND";
|
||||||
public static final String ITEM_USE_ACTIVITY_HAND = "USE_ACTIVITY_HAND";
|
public static final String ITEM_USE_ACTIVITY_HAND = "USE_ACTIVITY_HAND";
|
||||||
|
public static final String ITEM_LAST_HEARTBEAT = "LAST_HEARTBEAT";
|
||||||
|
|
||||||
private static final Logger logger = LoggerFactory.getLogger(QHybridSupport.class);
|
private static final Logger logger = LoggerFactory.getLogger(QHybridSupport.class);
|
||||||
|
|
||||||
@ -354,9 +356,8 @@ public class QHybridSupport extends QHybridBaseSupport {
|
|||||||
@Override
|
@Override
|
||||||
public void onFindDevice(boolean start) {
|
public void onFindDevice(boolean start) {
|
||||||
try {
|
try {
|
||||||
if (start && !watchAdapter.supportsExtendedVibration()) {
|
if (watchAdapter.supportsExtendedVibration()) {
|
||||||
GB.toast("Device does not support brr brr", Toast.LENGTH_SHORT, GB.INFO);
|
GB.toast("Device does not support brr brr", Toast.LENGTH_SHORT, GB.INFO);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
} catch (UnsupportedOperationException e) {
|
} catch (UnsupportedOperationException e) {
|
||||||
notifiyException(e);
|
notifiyException(e);
|
||||||
|
@ -40,6 +40,7 @@ public abstract class WatchAdapter {
|
|||||||
public abstract void syncNotificationSettings();
|
public abstract void syncNotificationSettings();
|
||||||
public abstract void onTestNewFunction();
|
public abstract void onTestNewFunction();
|
||||||
|
|
||||||
|
public abstract boolean supportsFindDevice();
|
||||||
public abstract boolean supportsExtendedVibration();
|
public abstract boolean supportsExtendedVibration();
|
||||||
public abstract boolean supportsActivityHand();
|
public abstract boolean supportsActivityHand();
|
||||||
public abstract String getModelName();
|
public abstract String getModelName();
|
||||||
|
@ -5,17 +5,18 @@ import android.bluetooth.BluetoothGattCharacteristic;
|
|||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import java.util.ArrayDeque;
|
import java.text.DateFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.GregorianCalendar;
|
import java.util.GregorianCalendar;
|
||||||
import java.util.Queue;
|
|
||||||
import java.util.TimeZone;
|
import java.util.TimeZone;
|
||||||
|
|
||||||
import nodomain.freeyourgadget.gadgetbridge.GBException;
|
import nodomain.freeyourgadget.gadgetbridge.GBException;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.devices.qhybrid.NotificationConfiguration;
|
import nodomain.freeyourgadget.gadgetbridge.devices.qhybrid.NotificationConfiguration;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.devices.qhybrid.PackageConfigHelper;
|
import nodomain.freeyourgadget.gadgetbridge.devices.qhybrid.PackageConfigHelper;
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.entities.NotificationFilter;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.model.GenericItem;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder;
|
import nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.QHybridSupport;
|
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.QHybridSupport;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.adapter.WatchAdapter;
|
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.adapter.WatchAdapter;
|
||||||
@ -23,9 +24,8 @@ import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.Req
|
|||||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.FossilRequest;
|
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.FossilRequest;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.configuration.ConfigurationGetRequest;
|
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.configuration.ConfigurationGetRequest;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.configuration.ConfigurationPutRequest;
|
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.configuration.ConfigurationPutRequest;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.file.FileGetRequest;
|
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.file.FileCloseRequest;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.file.FileLookupRequest;
|
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.file.FileDeleteRequest;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.file.FilePrepareRequest;
|
|
||||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.file.FilePutRequest;
|
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.file.FilePutRequest;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.notification.NotificationFilterPutRequest;
|
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.notification.NotificationFilterPutRequest;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.notification.PlayNotificationRequest;
|
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.notification.PlayNotificationRequest;
|
||||||
@ -47,10 +47,13 @@ public class FossilWatchAdapter extends WatchAdapter {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void initialize() {
|
public void initialize() {
|
||||||
playPairingAnimation();
|
// playPairingAnimation();
|
||||||
queueWrite(new ConfigurationGetRequest(this));
|
// queueWrite(new FileDeleteRequest((short) 0x0200));
|
||||||
|
// queueWrite(new ConfigurationGetRequest(this));
|
||||||
syncNotificationSettings();
|
//
|
||||||
|
// syncNotificationSettings();
|
||||||
|
getDeviceSupport().getDevice().setState(GBDevice.State.INITIALIZED);
|
||||||
|
getDeviceSupport().getDevice().sendDeviceUpdateIntent(getContext());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -153,26 +156,20 @@ public class FossilWatchAdapter extends WatchAdapter {
|
|||||||
PackageConfigHelper helper = new PackageConfigHelper(getContext());
|
PackageConfigHelper helper = new PackageConfigHelper(getContext());
|
||||||
final ArrayList<NotificationConfiguration> configurations = helper.getNotificationConfigurations();
|
final ArrayList<NotificationConfiguration> configurations = helper.getNotificationConfigurations();
|
||||||
if (configurations.size() == 1) configurations.add(configurations.get(0));
|
if (configurations.size() == 1) configurations.add(configurations.get(0));
|
||||||
queueWrite(new FilePrepareRequest((short) 0x0C00) {
|
queueWrite(new NotificationFilterPutRequest(configurations, FossilWatchAdapter.this) {
|
||||||
@Override
|
@Override
|
||||||
public void onPrepare() {
|
public void onFilePut(boolean success) {
|
||||||
super.onPrepare();
|
super.onFilePut(success);
|
||||||
queueWrite(new NotificationFilterPutRequest(configurations, FossilWatchAdapter.this) {
|
|
||||||
@Override
|
|
||||||
public void onFilePut(boolean success) {
|
|
||||||
super.onFilePut(success);
|
|
||||||
|
|
||||||
if (!success) {
|
if (!success) {
|
||||||
GB.toast("error writing notification settings", Toast.LENGTH_SHORT, GB.ERROR);
|
GB.toast("error writing notification settings", Toast.LENGTH_SHORT, GB.ERROR);
|
||||||
|
|
||||||
getDeviceSupport().getDevice().setState(GBDevice.State.NOT_CONNECTED);
|
getDeviceSupport().getDevice().setState(GBDevice.State.NOT_CONNECTED);
|
||||||
getDeviceSupport().getDevice().sendDeviceUpdateIntent(getContext());
|
getDeviceSupport().getDevice().sendDeviceUpdateIntent(getContext());
|
||||||
}
|
}
|
||||||
|
|
||||||
getDeviceSupport().getDevice().setState(GBDevice.State.INITIALIZED);
|
getDeviceSupport().getDevice().setState(GBDevice.State.INITIALIZED);
|
||||||
getDeviceSupport().getDevice().sendDeviceUpdateIntent(getContext());
|
getDeviceSupport().getDevice().sendDeviceUpdateIntent(getContext());
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} catch (GBException e) {
|
} catch (GBException e) {
|
||||||
@ -182,25 +179,23 @@ public class FossilWatchAdapter extends WatchAdapter {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onTestNewFunction() {
|
public void onTestNewFunction() {
|
||||||
try {
|
}
|
||||||
queueWrite(new NotificationFilterPutRequest(new PackageConfigHelper(getContext()).getNotificationConfigurations(), this));
|
|
||||||
} catch (GBException e) {
|
@Override
|
||||||
e.printStackTrace();
|
public boolean supportsFindDevice() {
|
||||||
}
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean supportsExtendedVibration() {
|
public boolean supportsExtendedVibration() {
|
||||||
/*String modelNumber = getDeviceSupport().getDevice().getModel();
|
String modelNumber = getDeviceSupport().getDevice().getModel();
|
||||||
switch (modelNumber) {
|
switch (modelNumber) {
|
||||||
case "HW.0.0":
|
case "HW.0.0":
|
||||||
return true;
|
return true;
|
||||||
case "HL.0.0":
|
case "HL.0.0":
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
throw new UnsupportedOperationException("model " + modelNumber + " not supported");*/
|
throw new UnsupportedOperationException("model " + modelNumber + " not supported");
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -229,15 +224,19 @@ public class FossilWatchAdapter extends WatchAdapter {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onFetchActivityData() {
|
public void onFetchActivityData() {
|
||||||
NotificationConfiguration config = new NotificationConfiguration((short) 0, (short) 0, (short) 0, null);
|
|
||||||
config.setPackageName("org.telegram.messenger");
|
// queueWrite(new ConfigurationPutRequest(new ConfigurationPutRequest.ConfigItem[0], this));
|
||||||
playNotification(config);
|
queueWrite(new ConfigurationPutRequest(new ConfigurationPutRequest.VibrationStrengthConfigItem((byte) 100), this));
|
||||||
// queueWrite(new ConfigurationGetRequest(this));
|
// queueWrite(new ConfigurationGetRequest(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCharacteristicChanged(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic) {
|
public boolean onCharacteristicChanged(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic) {
|
||||||
switch (characteristic.getUuid().toString()) {
|
switch (characteristic.getUuid().toString()) {
|
||||||
|
case "3dda0006-957f-7d4a-34a6-74696673696d": {
|
||||||
|
handleBackgroundCharacteristic(characteristic);
|
||||||
|
break;
|
||||||
|
}
|
||||||
case "3dda0002-957f-7d4a-34a6-74696673696d": {
|
case "3dda0002-957f-7d4a-34a6-74696673696d": {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -251,13 +250,14 @@ public class FossilWatchAdapter extends WatchAdapter {
|
|||||||
} catch (RuntimeException e) {
|
} catch (RuntimeException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
getDeviceSupport().notifiyException(e);
|
getDeviceSupport().notifiyException(e);
|
||||||
|
GB.toast(fossilRequest.getName() + " failed", Toast.LENGTH_SHORT, GB.ERROR);
|
||||||
requestFinished = true;
|
requestFinished = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (requestFinished) {
|
if (requestFinished) {
|
||||||
log(fossilRequest.getName() + " finished");
|
log(fossilRequest.getName() + " finished");
|
||||||
fossilRequest = null;
|
fossilRequest = null;
|
||||||
}else{
|
} else {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -271,11 +271,26 @@ public class FossilWatchAdapter extends WatchAdapter {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void handleBackgroundCharacteristic(BluetoothGattCharacteristic characteristic){
|
||||||
|
byte[] value = characteristic.getValue();
|
||||||
|
switch (value[1]){
|
||||||
|
case 2: {
|
||||||
|
byte syncId = value[2];
|
||||||
|
getDeviceSupport().getDevice().addDeviceInfo(new GenericItem(QHybridSupport.ITEM_LAST_HEARTBEAT, DateFormat.getTimeInstance().format(new Date())));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 8: {
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void log(String message) {
|
private void log(String message) {
|
||||||
Log.d("FossilWatchAdapter", message);
|
Log.d("FossilWatchAdapter", message);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void queueWrite(Request request){
|
public void queueWrite(Request request) {
|
||||||
this.queueWrite(request, false);
|
this.queueWrite(request, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -287,10 +302,10 @@ public class FossilWatchAdapter extends WatchAdapter {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (fossilRequest != null) {
|
if (fossilRequest != null) {
|
||||||
log( "queing request: " + request.getName());
|
log("queing request: " + request.getName());
|
||||||
if(priorise){
|
if (priorise) {
|
||||||
requestQueue.add(0, request);
|
requestQueue.add(0, request);
|
||||||
}else {
|
} else {
|
||||||
requestQueue.add(request);
|
requestQueue.add(request);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
|
@ -397,6 +397,11 @@ public class MisfitWatchAdapter extends WatchAdapter {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean supportsFindDevice() {
|
||||||
|
return supportsExtendedVibration();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean supportsExtendedVibration() {
|
public boolean supportsExtendedVibration() {
|
||||||
String modelNumber = getDeviceSupport().getDevice().getModel();
|
String modelNumber = getDeviceSupport().getDevice().getModel();
|
||||||
|
@ -1,7 +1,15 @@
|
|||||||
package nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil;
|
package nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.Request;
|
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.Request;
|
||||||
|
|
||||||
public abstract class FossilRequest extends Request {
|
public abstract class FossilRequest extends Request {
|
||||||
public abstract boolean isFinished();
|
public abstract boolean isFinished();
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public UUID getRequestUUID() {
|
||||||
|
return UUID.fromString("3dda0003-957f-7d4a-34a6-74696673696d");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,7 @@ import java.util.ArrayList;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.adapter.fossil.FossilWatchAdapter;
|
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.adapter.fossil.FossilWatchAdapter;
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.file.FileCloseAndPutRequest;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.file.FilePutRequest;
|
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.file.FilePutRequest;
|
||||||
|
|
||||||
public class ConfigurationPutRequest extends FilePutRequest {
|
public class ConfigurationPutRequest extends FilePutRequest {
|
||||||
@ -57,15 +58,25 @@ public class ConfigurationPutRequest extends FilePutRequest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public ConfigurationPutRequest(ConfigItem item, FossilWatchAdapter adapter) {
|
public ConfigurationPutRequest(ConfigItem item, FossilWatchAdapter adapter) {
|
||||||
super((short) 0x0800, createFileContent(item), adapter);
|
super((short) 0x0800, createFileContent(new ConfigItem[]{item}), adapter);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static byte[] createFileContent(ConfigItem item) {
|
public ConfigurationPutRequest(ConfigItem[] items, FossilWatchAdapter adapter) {
|
||||||
ByteBuffer buffer = ByteBuffer.allocate(item.getItemSize() + 3);
|
super((short) 0x0800, createFileContent(items), adapter);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static byte[] createFileContent(ConfigItem[] items) {
|
||||||
|
int overallSize = 0;
|
||||||
|
for(ConfigItem item : items){
|
||||||
|
overallSize += item.getItemSize() + 3;
|
||||||
|
}
|
||||||
|
ByteBuffer buffer = ByteBuffer.allocate(overallSize);
|
||||||
buffer.order(ByteOrder.LITTLE_ENDIAN);
|
buffer.order(ByteOrder.LITTLE_ENDIAN);
|
||||||
buffer.putShort(item.getId());
|
for(ConfigItem item : items){
|
||||||
buffer.put((byte) item.getItemSize());
|
buffer.putShort(item.getId());
|
||||||
buffer.put(item.getContent());
|
buffer.put((byte) item.getItemSize());
|
||||||
|
buffer.put(item.getContent());
|
||||||
|
}
|
||||||
|
|
||||||
return buffer.array();
|
return buffer.array();
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,37 @@
|
|||||||
|
package nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.file;
|
||||||
|
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.devices.qhybrid.NotificationConfiguration;
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.service.DeviceSupport;
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.adapter.fossil.FossilWatchAdapter;
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.notification.NotificationFilterPutRequest;
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.util.GB;
|
||||||
|
|
||||||
|
public class FileCloseAndPutRequest extends FileCloseRequest {
|
||||||
|
FossilWatchAdapter adapter;
|
||||||
|
byte[] data;
|
||||||
|
|
||||||
|
public FileCloseAndPutRequest(short fileHandle, byte[] data, FossilWatchAdapter adapter) {
|
||||||
|
super(fileHandle);
|
||||||
|
this.adapter = adapter;
|
||||||
|
this.data = data;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPrepare() {
|
||||||
|
super.onPrepare();
|
||||||
|
adapter.queueWrite(new FilePutRequest(getHandle(), this.data, adapter) {
|
||||||
|
@Override
|
||||||
|
public void onFilePut(boolean success) {
|
||||||
|
super.onFilePut(success);
|
||||||
|
FileCloseAndPutRequest.this.onFilePut(success);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onFilePut(boolean success){
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -9,11 +9,11 @@ import java.util.UUID;
|
|||||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.Request;
|
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.Request;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.FossilRequest;
|
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.FossilRequest;
|
||||||
|
|
||||||
public class FilePrepareRequest extends FossilRequest {
|
public class FileCloseRequest extends FossilRequest {
|
||||||
private boolean isFinished = false;
|
private boolean isFinished = false;
|
||||||
private short handle;
|
private short handle;
|
||||||
|
|
||||||
public FilePrepareRequest(short fileHandle) {
|
public FileCloseRequest(short fileHandle) {
|
||||||
this.handle = fileHandle;
|
this.handle = fileHandle;
|
||||||
ByteBuffer buffer = this.createBuffer();
|
ByteBuffer buffer = this.createBuffer();
|
||||||
buffer.putShort(fileHandle);
|
buffer.putShort(fileHandle);
|
||||||
@ -21,6 +21,10 @@ public class FilePrepareRequest extends FossilRequest {
|
|||||||
this.data = buffer.array();
|
this.data = buffer.array();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public short getHandle() {
|
||||||
|
return handle;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleResponse(BluetoothGattCharacteristic characteristic) {
|
public void handleResponse(BluetoothGattCharacteristic characteristic) {
|
||||||
super.handleResponse(characteristic);
|
super.handleResponse(characteristic);
|
@ -0,0 +1,59 @@
|
|||||||
|
package nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.file;
|
||||||
|
|
||||||
|
import android.bluetooth.BluetoothGattCharacteristic;
|
||||||
|
|
||||||
|
import java.nio.ByteBuffer;
|
||||||
|
import java.nio.ByteOrder;
|
||||||
|
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.FossilRequest;
|
||||||
|
|
||||||
|
public class FileDeleteRequest extends FossilRequest {
|
||||||
|
private boolean finished = false;
|
||||||
|
private short handle;
|
||||||
|
|
||||||
|
public FileDeleteRequest(short handle) {
|
||||||
|
this.handle = handle;
|
||||||
|
|
||||||
|
ByteBuffer buffer = createBuffer();
|
||||||
|
|
||||||
|
buffer.putShort(handle);
|
||||||
|
|
||||||
|
this.data = buffer.array();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void handleResponse(BluetoothGattCharacteristic characteristic) {
|
||||||
|
super.handleResponse(characteristic);
|
||||||
|
if(!characteristic.getUuid().toString().equals("3dda0003-957f-7d4a-34a6-74696673696d"))
|
||||||
|
throw new RuntimeException("wrong response UUID");
|
||||||
|
byte[] value = characteristic.getValue();
|
||||||
|
|
||||||
|
if(value.length != 4) throw new RuntimeException("wrong response length");
|
||||||
|
|
||||||
|
if(value[0] != (byte) 0x8B) throw new RuntimeException("wrong response start");
|
||||||
|
|
||||||
|
ByteBuffer buffer = ByteBuffer.wrap(value);
|
||||||
|
buffer.order(ByteOrder.LITTLE_ENDIAN);
|
||||||
|
|
||||||
|
if(buffer.getShort(1) != this.handle) throw new RuntimeException("wrong response handle");
|
||||||
|
|
||||||
|
if(buffer.get(3) != 0) throw new RuntimeException("wrong response status: " + buffer.get(3));
|
||||||
|
|
||||||
|
this.finished = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isFinished() {
|
||||||
|
return finished;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public byte[] getStartSequence() {
|
||||||
|
return new byte[]{(byte) 0x0B};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getPayloadLength() {
|
||||||
|
return 3;
|
||||||
|
}
|
||||||
|
}
|
@ -14,7 +14,7 @@ public abstract class FileLookupAndGetRequest extends FileLookupRequest {
|
|||||||
public void handleFileData(byte[] fileData) {
|
public void handleFileData(byte[] fileData) {
|
||||||
FileLookupAndGetRequest.this.handleFileData(fileData);
|
FileLookupAndGetRequest.this.handleFileData(fileData);
|
||||||
}
|
}
|
||||||
});
|
}, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract public void handleFileData(byte[] fileData);
|
abstract public void handleFileData(byte[] fileData);
|
||||||
|
@ -161,6 +161,7 @@ public class FilePutRequest extends FossilRequest {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 9: {
|
case 9: {
|
||||||
|
this.onFilePut(false);
|
||||||
throw new RuntimeException("file put timeout");
|
throw new RuntimeException("file put timeout");
|
||||||
/*timeout = true;
|
/*timeout = true;
|
||||||
ByteBuffer buffer2 = ByteBuffer.allocate(3);
|
ByteBuffer buffer2 = ByteBuffer.allocate(3);
|
||||||
|
@ -7,6 +7,7 @@ import java.util.zip.CRC32;
|
|||||||
|
|
||||||
import nodomain.freeyourgadget.gadgetbridge.devices.qhybrid.NotificationConfiguration;
|
import nodomain.freeyourgadget.gadgetbridge.devices.qhybrid.NotificationConfiguration;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.adapter.fossil.FossilWatchAdapter;
|
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.adapter.fossil.FossilWatchAdapter;
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.file.FileCloseAndPutRequest;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.file.FilePutRequest;
|
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.file.FilePutRequest;
|
||||||
|
|
||||||
public class NotificationFilterPutRequest extends FilePutRequest {
|
public class NotificationFilterPutRequest extends FilePutRequest {
|
||||||
|
Loading…
Reference in New Issue
Block a user