mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-11-28 04:46:51 +01:00
Fossil Hybrid: reformatted requests to avoid raw files
This commit is contained in:
parent
45df4cd35c
commit
d3dc6c4c5f
@ -22,12 +22,13 @@ import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.adapter.fossil.FossilWatchAdapter;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.file.FileLookupAndGetRequest;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.file.FileHandle;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.file.FileGetRequest;
|
||||
import nodomain.freeyourgadget.gadgetbridge.util.GB;
|
||||
|
||||
public class AlarmsGetRequest extends FileLookupAndGetRequest {
|
||||
public class AlarmsGetRequest extends FileGetRequest {
|
||||
public AlarmsGetRequest(FossilWatchAdapter adapter) {
|
||||
super((byte) 0x0A, adapter);
|
||||
super(FileHandle.ALARMS, adapter);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -35,14 +36,10 @@ public class AlarmsGetRequest extends FileLookupAndGetRequest {
|
||||
ByteBuffer buffer = ByteBuffer.wrap(fileData);
|
||||
buffer.order(ByteOrder.LITTLE_ENDIAN);
|
||||
|
||||
short handle = buffer.getShort(0);
|
||||
if(handle != (short) 0x0A00) throw new RuntimeException("wrong alarm handle");
|
||||
|
||||
int length = buffer.getInt(8) / 3;
|
||||
int length = fileData.length / 3;
|
||||
Alarm[] alarms = new Alarm[length];
|
||||
|
||||
for (int i = 0; i < length; i++){
|
||||
buffer.position(12 + i * 3);
|
||||
byte[] alarmBytes = new byte[]{
|
||||
buffer.get(),
|
||||
buffer.get(),
|
||||
@ -55,20 +52,5 @@ public class AlarmsGetRequest extends FileLookupAndGetRequest {
|
||||
}
|
||||
|
||||
public void handleAlarms(Alarm[] alarms){
|
||||
Alarm[] alarms2 = new Alarm[alarms.length];
|
||||
|
||||
for(int i = 0; i < alarms.length; i++){
|
||||
alarms2[i] = Alarm.fromBytes(alarms[i].getData());
|
||||
}
|
||||
// TODO: This does nothing currently!
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleFileLookupError(FILE_LOOKUP_ERROR error) {
|
||||
if(error == FILE_LOOKUP_ERROR.FILE_EMPTY){
|
||||
GB.toast("alarm file empty yet", Toast.LENGTH_LONG, GB.ERROR);
|
||||
}else{
|
||||
throw new RuntimeException("strange lookup stuff");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -22,29 +22,25 @@ import java.nio.ByteOrder;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.adapter.fossil.FossilWatchAdapter;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.buttonconfig.ConfigPayload;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.file.FileHandle;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.file.FileGetRawRequest;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.file.FileGetRequest;
|
||||
|
||||
public class ButtonConfigurationGetRequest extends FileGetRawRequest {
|
||||
public class ButtonConfigurationGetRequest extends FileGetRequest {
|
||||
public ButtonConfigurationGetRequest(FossilWatchAdapter adapter) {
|
||||
super(FileHandle.SETTINGS_BUTTONS, adapter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleFileRawData(byte[] fileData) {
|
||||
public void handleFileData(byte[] fileData) {
|
||||
log("fileData");
|
||||
|
||||
ByteBuffer buffer = ByteBuffer.wrap(fileData);
|
||||
buffer.order(ByteOrder.LITTLE_ENDIAN);
|
||||
|
||||
short fileHandle = buffer.getShort(0);
|
||||
// TODO check file handle
|
||||
// if(fileData != )
|
||||
|
||||
byte count = buffer.get(15);
|
||||
byte count = buffer.get(3);
|
||||
|
||||
ConfigPayload[] configs = new ConfigPayload[count];
|
||||
|
||||
buffer.position(16);
|
||||
buffer.position(4);
|
||||
for(int i = 0; i < count; i++){
|
||||
int buttonIndex = buffer.get() >> 4;
|
||||
int entryCount = buffer.get();
|
||||
|
@ -21,24 +21,18 @@ import nodomain.freeyourgadget.gadgetbridge.model.GenericItem;
|
||||
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.file.FileHandle;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.file.FileGetRawRequest;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.file.FileGetRequest;
|
||||
|
||||
public class ConfigurationGetRequest extends FileGetRawRequest {
|
||||
public class ConfigurationGetRequest extends FileGetRequest {
|
||||
public ConfigurationGetRequest(FossilWatchAdapter adapter) {
|
||||
super(FileHandle.CONFIGURATION, adapter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleFileRawData(byte[] fileData) {
|
||||
byte[] data = new byte[fileData.length - 12 - 4];
|
||||
|
||||
System.arraycopy(fileData, 12, data, 0, data.length);
|
||||
log("config file: " + getAdapter().arrayToString(fileData));
|
||||
log("config file: " + getAdapter().arrayToString(data));
|
||||
|
||||
public void handleFileData(byte[] fileData) {
|
||||
GBDevice device = getAdapter().getDeviceSupport().getDevice();
|
||||
|
||||
ConfigurationPutRequest.ConfigItem[] items = ConfigurationPutRequest.parsePayload(data);
|
||||
ConfigurationPutRequest.ConfigItem[] items = ConfigurationPutRequest.parsePayload(fileData);
|
||||
for(ConfigurationPutRequest.ConfigItem item : items){
|
||||
if(item instanceof ConfigurationPutRequest.VibrationStrengthConfigItem){
|
||||
device.addDeviceInfo(new GenericItem(QHybridSupport.ITEM_VIBRATION_STRENGTH, String.valueOf(((ConfigurationPutRequest.VibrationStrengthConfigItem) item).getValue())));
|
||||
|
@ -6,9 +6,9 @@ import java.util.ArrayList;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.adapter.fossil.FossilWatchAdapter;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.file.FileHandle;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.file.FileGetRawRequest;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.file.FileGetRequest;
|
||||
|
||||
public class GetDeviceInfoRequest extends FileGetRawRequest {
|
||||
public class GetDeviceInfoRequest extends FileGetRequest {
|
||||
enum INFO_CLASS{
|
||||
SUPPORTED_FILE_VERSIONS((short) 0x0a, SupportedFileVersionsInfo.class),
|
||||
;
|
||||
@ -41,14 +41,13 @@ public class GetDeviceInfoRequest extends FileGetRawRequest {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleFileRawData(byte[] fileData) {
|
||||
public void handleFileData(byte[] fileData) {
|
||||
ByteBuffer buffer = ByteBuffer.wrap(fileData);
|
||||
buffer.order(ByteOrder.LITTLE_ENDIAN);
|
||||
buffer.position(12);
|
||||
|
||||
ArrayList<DeviceInfo> deviceInfos = new ArrayList<>();
|
||||
|
||||
while(buffer.remaining() > 4){
|
||||
while(buffer.remaining() > 0){
|
||||
short type = buffer.getShort();
|
||||
int length = buffer.get();
|
||||
byte[] payload = new byte[length];
|
||||
|
@ -21,29 +21,16 @@ import java.nio.ByteOrder;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.adapter.fossil.FossilWatchAdapter;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.file.FileHandle;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.file.FileGetRawRequest;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.file.FileGetRequest;
|
||||
import nodomain.freeyourgadget.gadgetbridge.util.CRC32C;
|
||||
|
||||
public class NotificationFilterGetRequest extends FileGetRawRequest {
|
||||
public class NotificationFilterGetRequest extends FileGetRequest {
|
||||
public NotificationFilterGetRequest(FossilWatchAdapter adapter) {
|
||||
super(FileHandle.NOTIFICATION_FILTER, adapter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleFileRawData(byte[] fileData) {
|
||||
log("handleFileData");
|
||||
ByteBuffer buffer = ByteBuffer.wrap(fileData);
|
||||
buffer.order(ByteOrder.LITTLE_ENDIAN);
|
||||
public void handleFileData(byte[] fileData) {
|
||||
|
||||
byte[] data = new byte[fileData.length - 12 - 4];
|
||||
|
||||
System.arraycopy(fileData, 12, data, 0, data.length);
|
||||
|
||||
CRC32C crc32c = new CRC32C();
|
||||
crc32c.update(data,0,data.length);
|
||||
|
||||
if((int) crc32c.getValue() != buffer.getInt(fileData.length - 4)){
|
||||
throw new RuntimeException("CRC invalid");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -6,20 +6,18 @@ import java.util.ArrayList;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.adapter.fossil.FossilWatchAdapter;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.file.FileHandle;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.file.FileGetRawRequest;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.file.FileGetRequest;
|
||||
|
||||
public abstract class TranslationsGetRequest extends FileGetRawRequest {
|
||||
public abstract class TranslationsGetRequest extends FileGetRequest {
|
||||
public TranslationsGetRequest(FossilWatchAdapter adapter) {
|
||||
super(FileHandle.ASSET_TRANSLATIONS, adapter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleFileRawData(byte[] fileData) {
|
||||
public void handleFileData(byte[] fileData) {
|
||||
ByteBuffer buffer = ByteBuffer.wrap(fileData);
|
||||
buffer.order(ByteOrder.LITTLE_ENDIAN);
|
||||
|
||||
buffer.position(12);
|
||||
|
||||
byte[] localeBytes = new byte[5];
|
||||
buffer.get(localeBytes);
|
||||
String locale = new String(localeBytes);
|
||||
@ -28,7 +26,7 @@ public abstract class TranslationsGetRequest extends FileGetRawRequest {
|
||||
|
||||
ArrayList<TranslationItem> translations = new ArrayList<>();
|
||||
|
||||
while(buffer.remaining() > 4){
|
||||
while(buffer.remaining() > 0){
|
||||
int originalLength = buffer.getShort() - 1; // subtracting null terminator
|
||||
byte[] originalBytes = new byte[originalLength];
|
||||
buffer.get(originalBytes);
|
||||
|
Loading…
Reference in New Issue
Block a user