refactored requests

This commit is contained in:
Daniel Dakhno 2019-10-31 02:46:33 +01:00
parent e955330268
commit fc9016e98e
16 changed files with 100 additions and 247 deletions

View File

@ -358,6 +358,7 @@ public class QHybridSupport extends QHybridBaseSupport {
return; return;
} }
} catch (UnsupportedOperationException e) { } catch (UnsupportedOperationException e) {
notifiyException(e);
GB.toast("Please contact dakhnod@gmail.com\n", Toast.LENGTH_SHORT, GB.INFO); GB.toast("Please contact dakhnod@gmail.com\n", Toast.LENGTH_SHORT, GB.INFO);
} }
@ -478,6 +479,7 @@ public class QHybridSupport extends QHybridBaseSupport {
gbDevice.addDeviceInfo(new GenericItem(ITEM_EXTENDED_VIBRATION_SUPPORT, String.valueOf(watchAdapter.supportsExtendedVibration()))); gbDevice.addDeviceInfo(new GenericItem(ITEM_EXTENDED_VIBRATION_SUPPORT, String.valueOf(watchAdapter.supportsExtendedVibration())));
gbDevice.addDeviceInfo(new GenericItem(ITEM_HAS_ACTIVITY_HAND, String.valueOf(watchAdapter.supportsActivityHand()))); gbDevice.addDeviceInfo(new GenericItem(ITEM_HAS_ACTIVITY_HAND, String.valueOf(watchAdapter.supportsActivityHand())));
} catch (UnsupportedOperationException e) { } catch (UnsupportedOperationException e) {
notifiyException(e);
GB.toast("Please contact dakhnod@gmail.com\n", Toast.LENGTH_SHORT, GB.INFO); GB.toast("Please contact dakhnod@gmail.com\n", Toast.LENGTH_SHORT, GB.INFO);
gbDevice.addDeviceInfo(new GenericItem(ITEM_EXTENDED_VIBRATION_SUPPORT, "false")); gbDevice.addDeviceInfo(new GenericItem(ITEM_EXTENDED_VIBRATION_SUPPORT, "false"));
} }

View File

@ -9,7 +9,6 @@ import java.util.ArrayDeque;
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.NoSuchElementException;
import java.util.Queue; import java.util.Queue;
import java.util.TimeZone; import java.util.TimeZone;
@ -21,14 +20,15 @@ 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;
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.ConfigurationGetRequest; import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.FossilRequest;
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.ConfigurationPutRequest; import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.configuration.ConfigurationGetRequest;
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.FileGetRequest; import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.configuration.ConfigurationPutRequest;
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.FileLookupRequest; import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.file.FileGetRequest;
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.FilePrepareRequest; import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.file.FileLookupRequest;
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.FilePutRequest; import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.file.FilePrepareRequest;
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.NotificationFilterPutRequest; import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.file.FilePutRequest;
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.PlayNotificationRequest; 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.misfit.AnimationRequest; import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.misfit.AnimationRequest;
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.misfit.MoveHandsRequest; import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.misfit.MoveHandsRequest;
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.misfit.ReleaseHandsControlRequest; import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.misfit.ReleaseHandsControlRequest;
@ -36,12 +36,9 @@ import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.mis
import nodomain.freeyourgadget.gadgetbridge.util.GB; import nodomain.freeyourgadget.gadgetbridge.util.GB;
public class FossilWatchAdapter extends WatchAdapter { public class FossilWatchAdapter extends WatchAdapter {
private Queue<Request> requestQueue = new ArrayDeque<>(); private ArrayList<Request> requestQueue = new ArrayList<>();
FilePutRequest filePutRequest; FossilRequest fossilRequest;
FileGetRequest fileGetRequest;
FileLookupRequest fileLookupRequest;
FilePrepareRequest filePrepareRequest;
public FossilWatchAdapter(QHybridSupport deviceSupport) { public FossilWatchAdapter(QHybridSupport deviceSupport) {
super(deviceSupport); super(deviceSupport);
@ -51,14 +48,9 @@ public class FossilWatchAdapter extends WatchAdapter {
@Override @Override
public void initialize() { public void initialize() {
playPairingAnimation(); playPairingAnimation();
queueWrite(new ConfigurationGetRequest(this) { queueWrite(new ConfigurationGetRequest(this));
@Override
public void handleConfigurationLoaded() {
super.handleConfigurationLoaded();
syncNotificationSettings(); syncNotificationSettings();
}
});
} }
@Override @Override
@ -200,14 +192,16 @@ public class FossilWatchAdapter extends WatchAdapter {
@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
@ -246,94 +240,33 @@ public class FossilWatchAdapter extends WatchAdapter {
public boolean onCharacteristicChanged(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic) { public boolean onCharacteristicChanged(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic) {
switch (characteristic.getUuid().toString()) { switch (characteristic.getUuid().toString()) {
case "3dda0002-957f-7d4a-34a6-74696673696d": { case "3dda0002-957f-7d4a-34a6-74696673696d": {
if (fileGetRequest == null && fileLookupRequest == null && filePutRequest == null && filePrepareRequest == null) {
try {
queueWrite(requestQueue.remove());
} catch (NoSuchElementException e) {
log("requestsQueue empty");
}
}
break; break;
} }
case "3dda0004-957f-7d4a-34a6-74696673696d": case "3dda0004-957f-7d4a-34a6-74696673696d":
case "3dda0003-957f-7d4a-34a6-74696673696d": { case "3dda0003-957f-7d4a-34a6-74696673696d": {
if (filePutRequest != null) { if (fossilRequest != null) {
filePutRequest.handleResponse(characteristic);
if (filePutRequest.isFinished()) {
log("filePutRequets finished");
filePutRequest = null;
try {
queueWrite(requestQueue.remove());
} catch (NoSuchElementException e) {
log("requestsQueue empty");
}
}
} else if (fileGetRequest != null) {
boolean requestFinished; boolean requestFinished;
try { try {
fileGetRequest.handleResponse(characteristic); fossilRequest.handleResponse(characteristic);
requestFinished = fileGetRequest.isFinished(); requestFinished = fossilRequest.isFinished();
} catch (RuntimeException e) { } catch (RuntimeException e) {
e.printStackTrace(); e.printStackTrace();
getDeviceSupport().notifiyException(e);
requestFinished = true; requestFinished = true;
} }
if (requestFinished) { if (requestFinished) {
log("fileGetRequest finished"); log(fossilRequest.getName() + " finished");
fileGetRequest = null; fossilRequest = null;
try { }else{
queueWrite(requestQueue.remove()); return true;
} catch (NoSuchElementException e) {
log("requestsQueue empty");
}
}
} else if (fileLookupRequest != null) {
boolean requestFinished;
try {
fileLookupRequest.handleResponse(characteristic);
requestFinished = fileLookupRequest.isFinished();
} catch (RuntimeException e) {
e.printStackTrace();
requestFinished = true;
}
if (requestFinished) {
log("fileLookupRequest finished");
fileLookupRequest = null;
try {
queueWrite(requestQueue.remove());
} catch (NoSuchElementException e) {
log("requestsQueue empty");
}
}
} else if (filePrepareRequest != null) {
boolean requestFinished;
try {
filePrepareRequest.handleResponse(characteristic);
requestFinished = filePrepareRequest.isFinished();
} catch (RuntimeException e) {
e.printStackTrace();
requestFinished = true;
}
if (requestFinished) {
log("filePrepareRequest finished");
filePrepareRequest = null;
try {
queueWrite(requestQueue.remove());
} catch (NoSuchElementException e) {
log("requestsQueue empty");
}
}
} else {
try {
queueWrite(requestQueue.remove());
} catch (NoSuchElementException e) {
log("requestsQueue empty");
} }
} }
try {
queueWrite(requestQueue.remove(requestQueue.size() - 1));
} catch (ArrayIndexOutOfBoundsException e) {
log("requestsQueue empty");
}
} }
} }
return true; return true;
@ -343,26 +276,29 @@ public class FossilWatchAdapter extends WatchAdapter {
Log.d("FossilWatchAdapter", message); Log.d("FossilWatchAdapter", message);
} }
public void queueWrite(Request request) { public void queueWrite(Request request){
this.queueWrite(request, false);
}
public void queueWrite(Request request, boolean priorise) {
if (request.isBasicRequest()) { if (request.isBasicRequest()) {
try { try {
queueWrite(requestQueue.remove()); queueWrite(requestQueue.remove(requestQueue.size() - 1));
} catch (NoSuchElementException e) { } catch (ArrayIndexOutOfBoundsException e) {
} }
} else { } else {
if (filePutRequest != null || fileGetRequest != null || fileLookupRequest != null) { if (fossilRequest != null) {
Log.d("FossilWatchAdapter", "queing request: " + request.getName()); Log.d("requestQueue", "queing request: " + request.getName());
requestQueue.add(request); if(priorise){
requestQueue.add(0, request);
}else {
requestQueue.add(request);
}
return; return;
} }
log("executing request directly: " + request.getName()); Log.d("requestQueue", "executing request: " + request.getName());
if (request instanceof FilePutRequest) filePutRequest = (FilePutRequest) request; if (request instanceof FossilRequest) this.fossilRequest = (FossilRequest) request;
else if (request instanceof FileGetRequest) fileGetRequest = (FileGetRequest) request;
else if (request instanceof FileLookupRequest)
fileLookupRequest = (FileLookupRequest) request;
else if (request instanceof FilePrepareRequest)
filePrepareRequest = (FilePrepareRequest) request;
} }
new TransactionBuilder(request.getClass().getSimpleName()).write(getDeviceSupport().getCharacteristic(request.getRequestUUID()), request.getRequestData()).queue(getDeviceSupport().getQueue()); new TransactionBuilder(request.getClass().getSimpleName()).write(getDeviceSupport().getCharacteristic(request.getRequestUUID()), request.getRequestData()).queue(getDeviceSupport().getQueue());

View File

@ -42,7 +42,9 @@ public abstract class Request {
public void handleResponse(BluetoothGattCharacteristic characteristic){}; public void handleResponse(BluetoothGattCharacteristic characteristic){};
public String getName(){ public String getName(){
return this.getClass().getSimpleName(); Class thisClass = getClass();
while(thisClass.isAnonymousClass()) thisClass = thisClass.getSuperclass();
return thisClass.getSimpleName();
} }
protected void log(String message){ protected void log(String message){

View File

@ -0,0 +1,7 @@
package nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil;
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.Request;
public abstract class FossilRequest extends Request {
public abstract boolean isFinished();
}

View File

@ -1,24 +0,0 @@
package nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil;
import android.bluetooth.BluetoothGattCharacteristic;
import java.util.UUID;
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.Request;
public class PrepareFilesRequestOrWhatever extends Request {
@Override
public byte[] getStartSequence() {
return new byte[]{(byte) 0x09, (byte) 0xFF, (byte) 0xFF};
}
@Override
public void handleResponse(BluetoothGattCharacteristic characteristic) {
super.handleResponse(characteristic);
}
@Override
public UUID getRequestUUID() {
return UUID.fromString("3dda0003-957f-7d4a-34a6-74696673696d");
}
}

View File

@ -1,67 +0,0 @@
package nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil;
import java.io.ByteArrayOutputStream;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.charset.Charset;
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.adapter.fossil.FossilWatchAdapter;
public class SendNotificationFilterRequest extends FilePutRequest {
public SendNotificationFilterRequest(FossilWatchAdapter adapter) {
super((short) 0x0C00, createFile(), adapter);
}
private static byte[] createFile() {
return null;
/*ByteArrayOutputStream var3 = new ByteArrayOutputStream();
byte var1 = NotificationEntryId.APP_BUNDLE_CRC32.getId$blesdk_productionRelease();
byte[] var4 = ByteBuffer.allocate(4).order(ByteOrder.LITTLE_ENDIAN).putInt((int)this.appBundleCrc).array();
gwb.k(var4, "ByteBuffer.allocate(4)\n … .array()");
var3.write(this.c(var1, var4));
var3.write(this.c(NotificationEntryId.GROUP_ID.getId$blesdk_productionRelease(), new byte[]{this.groupId}));
boolean var2;
if (((CharSequence)this.sender).length() > 0) {
var2 = true;
} else {
var2 = false;
}
if (var2) {
var1 = NotificationEntryId.SENDER_NAME.getId$blesdk_productionRelease();
String var7 = bcf.da(this.sender);
Charset var5 = bdq.bqp.Qs();
if (var7 == null) {
throw new TypeCastException("null cannot be cast to non-null type java.lang.String");
}
var4 = var7.getBytes(var5);
gwb.k(var4, "(this as java.lang.String).getBytes(charset)");
var3.write(this.c(var1, var4));
}
if (this.priority != (short)-1) {
var3.write(this.c(NotificationEntryId.PRIORITY.getId$blesdk_productionRelease(), new byte[]{(byte)this.priority}));
}
NotificationHandMovingConfig var8 = this.handMovingConfig;
if (var8 != null) {
var3.write(this.c(NotificationEntryId.HAND_MOVING.getId$blesdk_productionRelease(), var8.getData$blesdk_productionRelease()));
}
NotificationVibePattern var9 = this.vibePattern;
if (var9 != null) {
var3.write(this.c(NotificationEntryId.VIBE.getId$blesdk_productionRelease(), new byte[]{var9.getId$blesdk_productionRelease()}));
}
NotificationIconConfig var10 = this.iconConfig;
if (var10 != null) {
var3.write(this.c(NotificationEntryId.ICON_IMAGE.getId$blesdk_productionRelease(), var10.getNotificationFilterIconConfigData$blesdk_productionRelease()));
}
byte[] var6 = var3.toByteArray();
var6 = ByteBuffer.allocate(var6.length + 2).order(ByteOrder.LITTLE_ENDIAN).putShort((short)var6.length).put(var6).array();
gwb.k(var6, "ByteBuffer\n …\n .array()");
return var6;*/
}
}

View File

@ -1,9 +1,10 @@
package nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil; package nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.configuration;
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice; import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
import nodomain.freeyourgadget.gadgetbridge.model.GenericItem; import nodomain.freeyourgadget.gadgetbridge.model.GenericItem;
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.QHybridSupport; import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.QHybridSupport;
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.FileLookupAndGetRequest;
public class ConfigurationGetRequest extends FileLookupAndGetRequest { public class ConfigurationGetRequest extends FileLookupAndGetRequest {
public ConfigurationGetRequest(FossilWatchAdapter adapter) { public ConfigurationGetRequest(FossilWatchAdapter adapter) {
@ -11,7 +12,7 @@ public class ConfigurationGetRequest extends FileLookupAndGetRequest {
} }
@Override @Override
void handleFileData(byte[] fileData) { public void handleFileData(byte[] fileData) {
byte[] data = new byte[fileData.length - 12 - 4]; byte[] data = new byte[fileData.length - 12 - 4];
System.arraycopy(fileData, 12, data, 0, data.length); System.arraycopy(fileData, 12, data, 0, data.length);

View File

@ -1,4 +1,4 @@
package nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil; package nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.configuration;
import android.graphics.Bitmap; import android.graphics.Bitmap;
@ -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.FilePutRequest;
public class ConfigurationPutRequest extends FilePutRequest { public class ConfigurationPutRequest extends FilePutRequest {
private static HashMap<Short, Class<? extends ConfigItem>> itemsById = new HashMap<>(); private static HashMap<Short, Class<? extends ConfigItem>> itemsById = new HashMap<>();

View File

@ -1,4 +1,4 @@
package nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil; package nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.file;
import android.bluetooth.BluetoothGattCharacteristic; import android.bluetooth.BluetoothGattCharacteristic;
@ -11,8 +11,9 @@ import java.util.zip.CRC32;
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.QHybridSupport; import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.QHybridSupport;
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.Request; import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.Request;
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.FossilRequest;
public abstract class FileGetRequest extends Request { public abstract class FileGetRequest extends FossilRequest {
private short handle; private short handle;
private FossilWatchAdapter adapter; private FossilWatchAdapter adapter;
@ -38,6 +39,7 @@ public abstract class FileGetRequest extends Request {
return adapter; return adapter;
} }
@Override
public boolean isFinished(){ public boolean isFinished(){
return finished; return finished;
} }
@ -110,5 +112,5 @@ public abstract class FileGetRequest extends Request {
return 11; return 11;
} }
abstract void handleFileData(byte[] fileData); abstract public void handleFileData(byte[] fileData);
} }

View File

@ -1,4 +1,4 @@
package nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil; package nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.file;
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.adapter.fossil.FossilWatchAdapter; import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.adapter.fossil.FossilWatchAdapter;
@ -11,11 +11,11 @@ public abstract class FileLookupAndGetRequest extends FileLookupRequest {
public void handleFileLookup(short fileHandle){ public void handleFileLookup(short fileHandle){
getAdapter().queueWrite(new FileGetRequest(getHandle(), getAdapter()) { getAdapter().queueWrite(new FileGetRequest(getHandle(), getAdapter()) {
@Override @Override
void handleFileData(byte[] fileData) { public void handleFileData(byte[] fileData) {
FileLookupAndGetRequest.this.handleFileData(fileData); FileLookupAndGetRequest.this.handleFileData(fileData);
} }
}); });
} }
abstract void handleFileData(byte[] fileData); abstract public void handleFileData(byte[] fileData);
} }

View File

@ -1,4 +1,4 @@
package nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil; package nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.file;
import android.bluetooth.BluetoothGattCharacteristic; import android.bluetooth.BluetoothGattCharacteristic;
@ -11,8 +11,9 @@ import java.util.zip.CRC32;
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.QHybridSupport; import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.QHybridSupport;
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.Request; import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.Request;
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.FossilRequest;
public class FileLookupRequest extends Request { public class FileLookupRequest extends FossilRequest {
private short handle = -1; private short handle = -1;
private byte fileType; private byte fileType;
@ -45,6 +46,7 @@ public class FileLookupRequest extends Request {
return handle; return handle;
} }
@Override
public boolean isFinished(){ public boolean isFinished(){
return finished; return finished;
} }

View File

@ -1,4 +1,4 @@
package nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil; package nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.file;
import android.bluetooth.BluetoothGattCharacteristic; import android.bluetooth.BluetoothGattCharacteristic;
@ -7,8 +7,9 @@ import java.nio.ByteOrder;
import java.util.UUID; 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;
public class FilePrepareRequest extends Request { public class FilePrepareRequest extends FossilRequest {
private boolean isFinished = false; private boolean isFinished = false;
private short handle; private short handle;
@ -62,6 +63,7 @@ public class FilePrepareRequest extends Request {
return 3; return 3;
} }
@Override
public boolean isFinished(){ public boolean isFinished(){
return this.isFinished; return this.isFinished;
} }

View File

@ -1,4 +1,4 @@
package nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil; package nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.file;
import android.bluetooth.BluetoothGattCharacteristic; import android.bluetooth.BluetoothGattCharacteristic;
import android.widget.Toast; import android.widget.Toast;
@ -13,10 +13,11 @@ import nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder;
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.CRC32C; import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.CRC32C;
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.Request; import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.Request;
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.FossilRequest;
import nodomain.freeyourgadget.gadgetbridge.util.GB; import nodomain.freeyourgadget.gadgetbridge.util.GB;
public class FilePutRequest extends Request { public class FilePutRequest extends FossilRequest {
public enum UploadState{INITIALIZED, UPLOADING, CLOSING, UPLOADED, ERROR} public enum UploadState{INITIALIZED, UPLOADING, CLOSING, UPLOADED}
public UploadState state; public UploadState state;
@ -59,9 +60,7 @@ public class FilePutRequest extends Request {
switch (responseType) { switch (responseType) {
case 3: { case 3: {
if (value.length != 5 || (value[0] & 0x0F) != 3) { if (value.length != 5 || (value[0] & 0x0F) != 3) {
this.state = UploadState.ERROR; throw new RuntimeException("wrong answer header");
log("wrong answer header");
break;
} }
state = UploadState.UPLOADING; state = UploadState.UPLOADING;
byte[] initialPacket = packets.get(0); byte[] initialPacket = packets.get(0);
@ -84,15 +83,11 @@ public class FilePutRequest extends Request {
byte status = value[3]; byte status = value[3];
if (status != 0) { if (status != 0) {
this.state = UploadState.ERROR; throw new RuntimeException("upload status: " + status);
log("file error: " + status);
break;
} }
if (handle != this.handle) { if (handle != this.handle) {
this.state = UploadState.ERROR; throw new RuntimeException("wrong response handle");
log("wrong file handle");
break;
} }
CRC32C realCrc = new CRC32C(); CRC32C realCrc = new CRC32C();
@ -100,8 +95,8 @@ public class FilePutRequest extends Request {
realCrc.update(data, 1, data.length - 1); realCrc.update(data, 1, data.length - 1);
if (crc != (int) realCrc.getValue()) { if (crc != (int) realCrc.getValue()) {
this.state = UploadState.ERROR; // this.state = UploadState.ERROR;
log("wrong crc"); // log("wrong crc");
// TODO CRC // TODO CRC
// break; // break;
} }
@ -138,9 +133,7 @@ public class FilePutRequest extends Request {
case 4: { case 4: {
if (value.length == 9) return; if (value.length == 9) return;
if (value.length != 4 || (value[0] & 0x0F) != 4) { if (value.length != 4 || (value[0] & 0x0F) != 4) {
this.state = UploadState.ERROR; throw new RuntimeException("wrong file closing header");
log("wrong closing header");
break;
} }
ByteBuffer buffer = ByteBuffer.wrap(value); ByteBuffer buffer = ByteBuffer.wrap(value);
buffer.order(ByteOrder.LITTLE_ENDIAN); buffer.order(ByteOrder.LITTLE_ENDIAN);
@ -148,21 +141,15 @@ public class FilePutRequest extends Request {
short handle = buffer.getShort(1); short handle = buffer.getShort(1);
if (handle != this.handle) { if (handle != this.handle) {
this.state = UploadState.ERROR;
log("wrong file handle");
onFilePut(false); onFilePut(false);
break; throw new RuntimeException("wrong file closing handle");
} }
byte status = buffer.get(3); byte status = buffer.get(3);
if (status != 0) { if (status != 0) {
this.state = UploadState.ERROR;
log("wrong closing handle");
onFilePut(false); onFilePut(false);
break; throw new RuntimeException("wrong closing status: " + status);
} }
this.state = UploadState.UPLOADED; this.state = UploadState.UPLOADED;
@ -193,8 +180,9 @@ public class FilePutRequest extends Request {
} }
} }
@Override
public boolean isFinished(){ public boolean isFinished(){
return this.state == UploadState.UPLOADED || this.state == UploadState.ERROR; return this.state == UploadState.UPLOADED;
} }
private void prepareFilePackets(byte[] file) { private void prepareFilePackets(byte[] file) {

View File

@ -1,12 +1,11 @@
package nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil; package nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.notification;
import android.util.Log;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.ByteOrder; import java.nio.ByteOrder;
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.CRC32C; import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.CRC32C;
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.FileGetRequest;
public class NotificationFilterGetRequest extends FileGetRequest { public class NotificationFilterGetRequest extends FileGetRequest {
public NotificationFilterGetRequest(FossilWatchAdapter adapter) { public NotificationFilterGetRequest(FossilWatchAdapter adapter) {
@ -14,7 +13,7 @@ public class NotificationFilterGetRequest extends FileGetRequest {
} }
@Override @Override
void handleFileData(byte[] fileData) { public void handleFileData(byte[] fileData) {
log("handleFileData"); log("handleFileData");
ByteBuffer buffer = ByteBuffer.wrap(fileData); ByteBuffer buffer = ByteBuffer.wrap(fileData);
buffer.order(ByteOrder.LITTLE_ENDIAN); buffer.order(ByteOrder.LITTLE_ENDIAN);

View File

@ -1,4 +1,4 @@
package nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil; package nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.notification;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.ByteOrder; import java.nio.ByteOrder;
@ -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.FilePutRequest;
public class NotificationFilterPutRequest extends FilePutRequest { public class NotificationFilterPutRequest extends FilePutRequest {
public NotificationFilterPutRequest(NotificationConfiguration[] configs, FossilWatchAdapter adapter) { public NotificationFilterPutRequest(NotificationConfiguration[] configs, FossilWatchAdapter adapter) {

View File

@ -1,4 +1,4 @@
package nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil; package nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.notification;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.ByteOrder; import java.nio.ByteOrder;
@ -6,6 +6,7 @@ import java.nio.charset.Charset;
import java.util.zip.CRC32; import java.util.zip.CRC32;
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.FilePutRequest;
public class PlayNotificationRequest extends FilePutRequest { public class PlayNotificationRequest extends FilePutRequest {