mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge.git
synced 2025-01-11 09:31:59 +01:00
added battery data fetching
This commit is contained in:
parent
082e135c6a
commit
462ee0e30b
@ -2,6 +2,9 @@ package nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.adapter.fos
|
||||
|
||||
import android.os.Build;
|
||||
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.devices.qhybrid.NotificationHRConfiguration;
|
||||
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.NotificationSpec;
|
||||
@ -13,6 +16,7 @@ import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fos
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil_hr.authentication.VerifyPrivateKeyRequest;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil_hr.information.GetDeviceInformationRequest;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil_hr.notification.NotificationFilterPutHRRequest;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil_hr.notification.NotificationImagePutRequest;
|
||||
|
||||
public class FossilHRWatchAdapter extends FossilWatchAdapter {
|
||||
private byte[] secretKey = new byte[]{(byte) 0x60, (byte) 0x26, (byte) 0xB7, (byte) 0xFD, (byte) 0xB2, (byte) 0x6D, (byte) 0x05, (byte) 0x5E, (byte) 0xDA, (byte) 0xF7, (byte) 0x4B, (byte) 0x49, (byte) 0x98, (byte) 0x78, (byte) 0x02, (byte) 0x38};
|
||||
@ -29,18 +33,15 @@ public class FossilHRWatchAdapter extends FossilWatchAdapter {
|
||||
queueWrite(new RequestMtuRequest(512));
|
||||
}
|
||||
|
||||
queueWrite(new VerifyPrivateKeyRequest(
|
||||
this.getSecretKey(),
|
||||
this
|
||||
));
|
||||
negotiateSymmetricKey();
|
||||
|
||||
/*try {
|
||||
try {
|
||||
FileInputStream fis = new FileInputStream("/sdcard/Q/images/icWhatsapp.icon");
|
||||
byte[] whatsappData = new byte[fis.available()];
|
||||
fis.read(whatsappData);
|
||||
fis.close();
|
||||
|
||||
fis = new FileInputStream("/sdcard/Q/images/icTwitter.icon");
|
||||
fis = new FileInputStream("/sdcard/Q/images/icEmail.icon");
|
||||
byte[] twitterData = new byte[fis.available()];
|
||||
fis.read(twitterData);
|
||||
fis.close();
|
||||
@ -57,24 +58,40 @@ public class FossilHRWatchAdapter extends FossilWatchAdapter {
|
||||
this));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}*/ // icons
|
||||
} // icons
|
||||
|
||||
queueWrite(new NotificationFilterPutHRRequest(new NotificationHRConfiguration[]{
|
||||
new NotificationHRConfiguration("com.whatsapp", -1),
|
||||
new NotificationHRConfiguration("generic", -1),
|
||||
new NotificationHRConfiguration("asdasdasdasdasd", -1),
|
||||
// new NotificationHRConfiguration("twitter", -1),
|
||||
}, this));
|
||||
|
||||
queueWrite(new PlayNotificationRequest("com.whatsapp", "WhatsAp", "wHATSaPP", this));
|
||||
queueWrite(new PlayNotificationRequest("twitter", "Twitter", "tWITTER", this));
|
||||
queueWrite(new PlayNotificationRequest("twitterrrr", "Twitterr", "tWITTER", this));
|
||||
|
||||
queueWrite(new GetDeviceInformationRequest(this));
|
||||
|
||||
// syncConfiguration();
|
||||
syncSettings();
|
||||
|
||||
queueWrite(new SetDeviceStateRequest(GBDevice.State.INITIALIZED));
|
||||
}
|
||||
|
||||
private void negotiateSymmetricKey(){
|
||||
queueWrite(new VerifyPrivateKeyRequest(
|
||||
this.getSecretKey(),
|
||||
this
|
||||
));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFetchActivityData() {
|
||||
syncSettings();
|
||||
}
|
||||
|
||||
private void syncSettings(){
|
||||
negotiateSymmetricKey();
|
||||
|
||||
queueWrite(new GetDeviceInformationRequest(this));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setActivityHand(double progress) {
|
||||
// super.setActivityHand(progress);
|
||||
|
@ -32,14 +32,14 @@ public class ConfigurationPutRequest extends FilePutRequest {
|
||||
private static HashMap<Short, Class<? extends ConfigItem>> itemsById = new HashMap<>();
|
||||
|
||||
static {
|
||||
itemsById.put((short)3, DailyStepGoalConfigItem.class);
|
||||
itemsById.put((short)10, VibrationStrengthConfigItem.class);
|
||||
itemsById.put((short)2, CurrentStepCountConfigItem.class);
|
||||
itemsById.put((short)3, DailyStepGoalConfigItem.class);
|
||||
itemsById.put((short)12, TimeConfigItem.class);
|
||||
itemsById.put((short)0x02, CurrentStepCountConfigItem.class);
|
||||
itemsById.put((short)0x03, DailyStepGoalConfigItem.class);
|
||||
itemsById.put((short)0x0A, VibrationStrengthConfigItem.class);
|
||||
itemsById.put((short)0x0C, TimeConfigItem.class);
|
||||
itemsById.put((short)0x0D, BatteryConfigItem.class);
|
||||
}
|
||||
|
||||
static ConfigItem[] parsePayload(byte[] data) {
|
||||
public static ConfigItem[] parsePayload(byte[] data) {
|
||||
ByteBuffer buffer = ByteBuffer.wrap(data);
|
||||
buffer.order(ByteOrder.LITTLE_ENDIAN);
|
||||
|
||||
@ -192,6 +192,42 @@ public class ConfigurationPutRequest extends FilePutRequest {
|
||||
}
|
||||
}
|
||||
|
||||
static public class BatteryConfigItem extends ConfigItem{
|
||||
private int batteryPercentage, batteryVoltage;
|
||||
|
||||
public int getBatteryPercentage() {
|
||||
return batteryPercentage;
|
||||
}
|
||||
|
||||
public int getBatteryVoltage() {
|
||||
return batteryVoltage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemSize() {
|
||||
return 3;
|
||||
}
|
||||
|
||||
@Override
|
||||
public short getId() {
|
||||
return 0x0D;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] getContent() {
|
||||
return new byte[0];
|
||||
}
|
||||
|
||||
@Override
|
||||
public void parseData(byte[] data) {
|
||||
ByteBuffer buffer = ByteBuffer.wrap(data);
|
||||
buffer.order(ByteOrder.LITTLE_ENDIAN);
|
||||
|
||||
this.batteryVoltage = buffer.getShort();
|
||||
this.batteryPercentage = buffer.get();
|
||||
}
|
||||
}
|
||||
|
||||
static public class DailyStepGoalConfigItem extends GenericConfigItem<Integer> {
|
||||
public DailyStepGoalConfigItem(){
|
||||
this(-1);
|
||||
|
@ -27,6 +27,8 @@ import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.utils.String
|
||||
|
||||
public class PlayNotificationRequest extends FilePutRequest {
|
||||
|
||||
static int id = 0;
|
||||
|
||||
public PlayNotificationRequest(String packageName, FossilWatchAdapter adapter) {
|
||||
super((short) 0x0900, createFile(packageName, packageName, packageName), adapter);
|
||||
}
|
||||
@ -60,30 +62,25 @@ public class PlayNotificationRequest extends FilePutRequest {
|
||||
|
||||
short mainBufferLength = (short) (lengthBufferLength + uidLength + appBundleCRCLength + titleBytes.length + senderBytes.length + messageBytes.length);
|
||||
|
||||
ByteBuffer lengthBuffer = ByteBuffer.allocate(lengthBufferLength);
|
||||
lengthBuffer.order(ByteOrder.LITTLE_ENDIAN);
|
||||
lengthBuffer.putShort(mainBufferLength);
|
||||
lengthBuffer.put(lengthBufferLength);
|
||||
lengthBuffer.put(typeId);
|
||||
lengthBuffer.put(flags);
|
||||
lengthBuffer.put(uidLength);
|
||||
lengthBuffer.put(appBundleCRCLength);
|
||||
lengthBuffer.put((byte) titleBytes.length);
|
||||
lengthBuffer.put((byte) senderBytes.length);
|
||||
lengthBuffer.put((byte) messageBytes.length);
|
||||
|
||||
ByteBuffer mainBuffer = ByteBuffer.allocate(mainBufferLength);
|
||||
mainBuffer.order(ByteOrder.LITTLE_ENDIAN);
|
||||
mainBuffer.put(lengthBuffer.array());
|
||||
|
||||
lengthBuffer = ByteBuffer.allocate(mainBufferLength - lengthBufferLength);
|
||||
lengthBuffer.order(ByteOrder.LITTLE_ENDIAN);
|
||||
lengthBuffer.putInt(10); // messageId
|
||||
lengthBuffer.putInt(packageCrc);
|
||||
lengthBuffer.put(titleBytes);
|
||||
lengthBuffer.put(senderBytes);
|
||||
lengthBuffer.put(messageBytes);
|
||||
mainBuffer.put(lengthBuffer.array());
|
||||
mainBuffer.putShort(mainBufferLength);
|
||||
|
||||
mainBuffer.put(lengthBufferLength);
|
||||
mainBuffer.put(typeId);
|
||||
mainBuffer.put(flags);
|
||||
mainBuffer.put(uidLength);
|
||||
mainBuffer.put(appBundleCRCLength);
|
||||
mainBuffer.put((byte) titleBytes.length);
|
||||
mainBuffer.put((byte) senderBytes.length);
|
||||
mainBuffer.put((byte) messageBytes.length);
|
||||
|
||||
mainBuffer.putInt(id++); // messageId
|
||||
mainBuffer.putInt(packageCrc);
|
||||
mainBuffer.put(titleBytes);
|
||||
mainBuffer.put(senderBytes);
|
||||
mainBuffer.put(messageBytes);
|
||||
return mainBuffer.array();
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,11 @@
|
||||
package nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil_hr.information;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
||||
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.adapter.fossil_hr.FossilHRWatchAdapter;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.configuration.ConfigurationPutRequest;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil_hr.file.FileEncryptedGetRequest;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil_hr.file.FileEncryptedLookupAndGetRequest;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.utils.StringUtils;
|
||||
@ -13,6 +17,32 @@ public class GetDeviceInformationRequest extends FileEncryptedLookupAndGetReques
|
||||
|
||||
@Override
|
||||
public void handleFileData(byte[] fileData) {
|
||||
log("device info: " + StringUtils.bytesToHex(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));
|
||||
|
||||
GBDevice device = getAdapter().getDeviceSupport().getDevice();
|
||||
|
||||
ConfigurationPutRequest.ConfigItem[] items = ConfigurationPutRequest.parsePayload(data);
|
||||
|
||||
for(ConfigurationPutRequest.ConfigItem item : items){
|
||||
if(item instanceof ConfigurationPutRequest.VibrationStrengthConfigItem){
|
||||
device.addDeviceInfo(new GenericItem(QHybridSupport.ITEM_VIBRATION_STRENGTH, String.valueOf(((ConfigurationPutRequest.VibrationStrengthConfigItem) item).getValue())));
|
||||
}else if(item instanceof ConfigurationPutRequest.DailyStepGoalConfigItem){
|
||||
device.addDeviceInfo(new GenericItem(QHybridSupport.ITEM_STEP_GOAL, String.valueOf(((ConfigurationPutRequest.DailyStepGoalConfigItem) item).getValue())));
|
||||
}else if(item instanceof ConfigurationPutRequest.CurrentStepCountConfigItem){
|
||||
device.addDeviceInfo(new GenericItem(QHybridSupport.ITEM_STEP_COUNT, String.valueOf(((ConfigurationPutRequest.CurrentStepCountConfigItem) item).getValue())));
|
||||
}else if(item instanceof ConfigurationPutRequest.TimezoneOffsetConfigItem) {
|
||||
device.addDeviceInfo(new GenericItem(QHybridSupport.ITEM_TIMEZONE_OFFSET, String.valueOf(((ConfigurationPutRequest.TimezoneOffsetConfigItem) item).getValue())));
|
||||
}else if(item instanceof ConfigurationPutRequest.BatteryConfigItem){
|
||||
device.setBatteryLevel((short) ((ConfigurationPutRequest.BatteryConfigItem) item).getBatteryPercentage());
|
||||
device.setBatteryVoltage(((ConfigurationPutRequest.BatteryConfigItem) item).getBatteryVoltage() / 1000f);
|
||||
device.setBatteryThresholdPercent((short) 15);
|
||||
}
|
||||
}
|
||||
|
||||
device.sendDeviceUpdateIntent(getAdapter().getContext());
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user