1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-27 20:36:51 +01:00

Huawei: DeviceReportThreshold command added

This commit is contained in:
Me7c7 2024-09-20 20:22:35 +03:00 committed by José Rebelo
parent ee1b71a240
commit 028ff619b7
5 changed files with 108 additions and 3 deletions

View File

@ -356,7 +356,6 @@ public class HuaweiCoordinator {
return supportsCommandForService(0x02, 0x08);
}
public boolean supportsMotionGoal() {
return supportsCommandForService(0x07, 0x01);
}
@ -369,6 +368,10 @@ public class HuaweiCoordinator {
return supportsCommandForService(0x07, 0x07);
}
public boolean supportsDeviceReportThreshold() {
return supportsCommandForService(0x07, 0x0e);
}
public boolean supportsTruSleep() {
return supportsCommandForService(0x07, 0x16);
}
@ -402,8 +405,6 @@ public class HuaweiCoordinator {
}
public boolean supportsFitnessThresholdValueV2() { return supportsExpandCapability(0x9a) || supportsExpandCapability(0x9c); }
// 0x1d - SupportTemperature
// 0xba - SupportTemperatureClassification
// 0x43 - SupportTemperatureStudy

View File

@ -0,0 +1,41 @@
package nodomain.freeyourgadget.gadgetbridge.devices.huawei;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
public class HuaweiReportThreshold {
private int dataType;
private int valueType;
private int value;
private int action;
public HuaweiReportThreshold(int dataType, int valueType, int value, int action) {
this.dataType = dataType;
this.valueType = valueType;
this.value = value;
this.action = action;
}
public byte[] getBytes() {
ByteBuffer buffer = ByteBuffer.allocate(5);
buffer.put((byte) dataType);
buffer.put((byte) valueType);
buffer.putShort((short) value);
buffer.put((byte) action);
return buffer.array();
}
public static List<HuaweiReportThreshold> getReportThresholds() {
List<HuaweiReportThreshold> thresholds = new ArrayList<>();
thresholds.add(new HuaweiReportThreshold(1,3, 500, 2));
thresholds.add(new HuaweiReportThreshold(3,3, 100, 2));
int current_hour = Calendar.getInstance().get(Calendar.HOUR_OF_DAY);
int value = (current_hour < 6)?21600:3600;
thresholds.add(new HuaweiReportThreshold(4,3, value, 2));
return thresholds;
}
}

View File

@ -21,6 +21,7 @@ import java.util.Arrays;
import java.util.List;
import nodomain.freeyourgadget.gadgetbridge.devices.huawei.HuaweiPacket;
import nodomain.freeyourgadget.gadgetbridge.devices.huawei.HuaweiReportThreshold;
import nodomain.freeyourgadget.gadgetbridge.devices.huawei.HuaweiTLV;
public class FitnessData {
@ -466,6 +467,25 @@ public class FitnessData {
}
}
public static class DeviceReportThreshold {
public static final byte id = 0xe;
public static class Request extends HuaweiPacket {
public Request(ParamsProvider paramsProvider, List<HuaweiReportThreshold> thresholds) {
super(paramsProvider);
this.serviceId = FitnessData.id;
this.commandId = id;
this.tlv = new HuaweiTLV();
for(HuaweiReportThreshold th: thresholds) {
this.tlv.put(0x02, th.getBytes());
}
this.complete = true;
}
}
}
public static class TruSleep {
public static final byte id = 0x16;

View File

@ -102,6 +102,7 @@ import nodomain.freeyourgadget.gadgetbridge.service.devices.huawei.requests.GetN
import nodomain.freeyourgadget.gadgetbridge.service.devices.huawei.requests.GetSmartAlarmList;
import nodomain.freeyourgadget.gadgetbridge.service.devices.huawei.requests.GetWatchfaceParams;
import nodomain.freeyourgadget.gadgetbridge.service.devices.huawei.requests.SendCameraRemoteSetupEvent;
import nodomain.freeyourgadget.gadgetbridge.service.devices.huawei.requests.SendDeviceReportThreshold;
import nodomain.freeyourgadget.gadgetbridge.service.devices.huawei.requests.SendExtendedAccountRequest;
import nodomain.freeyourgadget.gadgetbridge.service.devices.huawei.requests.SendFitnessUserInfoRequest;
import nodomain.freeyourgadget.gadgetbridge.service.devices.huawei.requests.SendGpsAndTimeToDeviceRequest;
@ -725,6 +726,7 @@ public class HuaweiSupportProvider {
initRequestQueue.add(new SendNotifyHeartRateCapabilityRequest(this));
initRequestQueue.add(new SendNotifyRestHeartRateCapabilityRequest(this));
initRequestQueue.add(new SendRunPaceConfigRequest(this));
initRequestQueue.add(new SendDeviceReportThreshold(this));
initRequestQueue.add(new SetMediumToStrengthThresholdRequest(this));
initRequestQueue.add(new SendFitnessGoalRequest(this));
initRequestQueue.add(new GetNotificationCapabilitiesRequest(this));

View File

@ -0,0 +1,41 @@
package nodomain.freeyourgadget.gadgetbridge.service.devices.huawei.requests;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.List;
import nodomain.freeyourgadget.gadgetbridge.devices.huawei.HuaweiPacket;
import nodomain.freeyourgadget.gadgetbridge.devices.huawei.HuaweiReportThreshold;
import nodomain.freeyourgadget.gadgetbridge.devices.huawei.packets.FitnessData;
import nodomain.freeyourgadget.gadgetbridge.service.devices.huawei.HuaweiSupportProvider;
public class SendDeviceReportThreshold extends Request {
private static final Logger LOG = LoggerFactory.getLogger(SendDeviceReportThreshold.class);
public SendDeviceReportThreshold(HuaweiSupportProvider support) {
super(support);
this.serviceId = FitnessData.id;
this.commandId = FitnessData.DeviceReportThreshold.id;
}
@Override
protected boolean requestSupported() {
return supportProvider.getHuaweiCoordinator().supportsDeviceReportThreshold();
}
@Override
protected List<byte[]> createRequest() throws RequestCreationException {
try {
return new FitnessData.DeviceReportThreshold.Request(paramsProvider, HuaweiReportThreshold.getReportThresholds()).serialize();
} catch (HuaweiPacket.CryptoException e) {
throw new RequestCreationException(e);
}
}
@Override
protected void processResponse() {
LOG.debug("handle Send Device Report Threshold");
}
}