Amazfit Bip: initial support for fetching debug logs from the watch

TODO:
- fix wrong toast about start time
- properly create an API for this kind of stuff (currently uses testNewFunction())
This commit is contained in:
Andreas Shimokawa 2017-09-18 23:24:11 +02:00
parent 35e59d0add
commit 412153364e
6 changed files with 17 additions and 9 deletions

View File

@ -24,4 +24,6 @@ public class AmazfitBipService {
// goes to UUID_CHARACTERISTIC_3_CONFIGURATION, TODO: validate this for Mi Band 2, it maybe triggers more than only GPS version...
public static final byte[] COMMAND_REQUEST_GPS_VERSION = new byte[]{0x0e};
public static final byte COMMAND_ACTIVITY_DATA_TYPE_DEBUGLOGS = 0x07;
}

View File

@ -104,7 +104,7 @@ public class MiBand2Service {
public static final byte AUTH_BYTE = 0x8;
// maybe not really activity data, but steps?
public static final byte COMMAND_FETCH_ACTIVITY_DATA = 0x02;
public static final byte COMMAND_FETCH_DATA = 0x02;
public static final byte COMMAND_XXXX_ACTIVITY_DATA = 0x03; // maybe delete/drop activity data?
public static final byte[] COMMAND_SET_FITNESS_GOAL_START = new byte[] { 0x10, 0x0, 0x0 };
@ -176,7 +176,7 @@ public class MiBand2Service {
public static final byte COMMAND_ACTIVITY_DATA_START_DATE = 0x01;
public static final byte COMMAND_ACTIVITY_DATA_TYPE_ACTIVTY = 0x01;
public static final byte COMMAND_ACTIVITY_DATA_TYPE_UNKNOWN_2 = 0x02;
public static final byte COMMAND_ACTIVITY_DATA_XXX_DATE = 0x02; // issued on first connect, followd by COMMAND_XXXX_ACTIVITY_DATA instead of COMMAND_FETCH_ACTIVITY_DATA
public static final byte COMMAND_ACTIVITY_DATA_XXX_DATE = 0x02; // issued on first connect, followd by COMMAND_XXXX_ACTIVITY_DATA instead of COMMAND_FETCH_DATA
public static final byte COMMAND_FIRMWARE_INIT = 0x01; // to UUID_CHARACTERISTIC_FIRMWARE, followed by fw file size in bytes
public static final byte COMMAND_FIRMWARE_START_DATA = 0x03; // to UUID_CHARACTERISTIC_FIRMWARE

View File

@ -43,6 +43,7 @@ import nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder;
import nodomain.freeyourgadget.gadgetbridge.service.btle.profiles.alertnotification.AlertCategory;
import nodomain.freeyourgadget.gadgetbridge.service.btle.profiles.alertnotification.AlertNotificationProfile;
import nodomain.freeyourgadget.gadgetbridge.service.btle.profiles.alertnotification.NewAlert;
import nodomain.freeyourgadget.gadgetbridge.service.devices.amazfitbip.operations.AmazfitBipFetchLogsOperation;
import nodomain.freeyourgadget.gadgetbridge.service.devices.amazfitbip.operations.AmazfitBipUpdateFirmwareOperation;
import nodomain.freeyourgadget.gadgetbridge.service.devices.miband.NotificationStrategy;
import nodomain.freeyourgadget.gadgetbridge.service.devices.miband2.MiBand2Support;
@ -224,6 +225,15 @@ public class AmazfitBipSupport extends MiBand2Support {
}
}
@Override
public void onTestNewFunction() {
try {
new AmazfitBipFetchLogsOperation(this).perform();
} catch (IOException ex) {
LOG.error("Unable to fetch logs", ex);
}
}
@Override
public boolean onCharacteristicChanged(BluetoothGatt gatt,
BluetoothGattCharacteristic characteristic) {

View File

@ -132,10 +132,6 @@ public abstract class AbstractFetchOperation extends AbstractMiBand2Operation {
*/
protected abstract void handleActivityNotif(byte[] value);
/**
* Creates samples from the given 17-length array
* @param value
*/
protected abstract void bufferActivityData(byte[] value);
protected void handleActivityMetadata(byte[] value) {
@ -146,7 +142,7 @@ public abstract class AbstractFetchOperation extends AbstractMiBand2Operation {
// the 4th - 7th bytes probably somehow represent the number of bytes/packets to expect
// last 8 bytes are the start date
Calendar startTimestamp = getSupport().fromTimeBytes(org.apache.commons.lang3.ArrayUtils.subarray(value, 7, value.length));
Calendar startTimestamp = getSupport().fromTimeBytes(Arrays.copyOfRange(value, 7, value.length));
setStartTimestamp(startTimestamp);
GB.toast(getContext().getString(R.string.FetchActivityOperation_about_to_transfer_since,

View File

@ -71,7 +71,7 @@ public class FetchActivityOperation extends AbstractFetchOperation {
builder.write(characteristicFetch, BLETypeConversions.join(new byte[] { MiBand2Service.COMMAND_ACTIVITY_DATA_START_DATE, MiBand2Service.COMMAND_ACTIVITY_DATA_TYPE_ACTIVTY }, getSupport().getTimeBytes(sinceWhen, TimeUnit.MINUTES)));
builder.add(new WaitAction(1000)); // TODO: actually wait for the success-reply
builder.notify(characteristicActivityData, true);
builder.write(characteristicFetch, new byte[] { MiBand2Service.COMMAND_FETCH_ACTIVITY_DATA });
builder.write(characteristicFetch, new byte[] { MiBand2Service.COMMAND_FETCH_DATA});
}
protected void handleActivityFetchFinish() {

View File

@ -60,7 +60,7 @@ public class FetchSportsSummaryOperation extends AbstractFetchOperation {
// getSupport().getTimeBytes(sinceWhen, TimeUnit.MINUTES)));
// builder.add(new WaitAction(1000)); // TODO: actually wait for the success-reply
// builder.notify(characteristicActivityData, true);
// builder.write(characteristicFetch, new byte[] { MiBand2Service.COMMAND_FETCH_ACTIVITY_DATA });
// builder.write(characteristicFetch, new byte[] { MiBand2Service.COMMAND_FETCH_DATA });
}
@Override