mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-06-10 07:07:57 +02:00
3a58314db6
- communication protocols - device support implementation - download FIT file storage Features: - basic connectivity: time sync, battery status, HW/FW version info - real-time activity tracking - fitness data sync - find the device, find the phone - factory reset Features implemented but not working: - notifications: fully implemented, seem to communicate correctly, but not shown on watch Features implemented partially (not expected to work now): - weather information (and in future possibly weather alerts) - music info - firmware update: only the initial file upload implemented, not used Things to improve/change: - Device name hardcoded in `VivomoveHrCoordinator.getSupportedType`, service UUIDs not available - Download FIT file storage: Should be store (and offer the user to export?) the FIT data forever? - Obviously, various code improvements, cleanup, etc.
45 lines
2.1 KiB
Java
45 lines
2.1 KiB
Java
package nodomain.freeyourgadget.gadgetbridge.service.devices.vivomovehr.messages;
|
|
|
|
import nodomain.freeyourgadget.gadgetbridge.devices.vivomovehr.VivomoveConstants;
|
|
import nodomain.freeyourgadget.gadgetbridge.service.devices.vivomovehr.BinaryUtils;
|
|
import nodomain.freeyourgadget.gadgetbridge.service.devices.vivomovehr.ChecksumCalculator;
|
|
import nodomain.freeyourgadget.gadgetbridge.service.devices.vivomovehr.GarminDeviceSetting;
|
|
|
|
import java.util.Map;
|
|
|
|
public class SetDeviceSettingsMessage {
|
|
public final byte[] packet;
|
|
|
|
public SetDeviceSettingsMessage(Map<GarminDeviceSetting, Object> settings) {
|
|
final int settingsCount = settings.size();
|
|
if (settingsCount == 0) throw new IllegalArgumentException("Empty settings");
|
|
if (settingsCount > 255) throw new IllegalArgumentException("Too many settings");
|
|
|
|
final MessageWriter writer = new MessageWriter();
|
|
writer.writeShort(0); // packet size will be filled below
|
|
writer.writeShort(VivomoveConstants.MESSAGE_DEVICE_SETTINGS);
|
|
writer.writeByte(settings.size());
|
|
for (Map.Entry<GarminDeviceSetting, Object> settingPair : settings.entrySet()) {
|
|
final GarminDeviceSetting setting = settingPair.getKey();
|
|
writer.writeByte(setting.ordinal());
|
|
final Object value = settingPair.getValue();
|
|
if (value instanceof String) {
|
|
writer.writeString((String) value);
|
|
} else if (value instanceof Integer) {
|
|
writer.writeByte(4);
|
|
writer.writeInt((Integer) value);
|
|
} else if (value instanceof Boolean) {
|
|
writer.writeByte(1);
|
|
writer.writeByte(Boolean.TRUE.equals(value) ? 1 : 0);
|
|
} else {
|
|
throw new IllegalArgumentException("Unsupported setting value type " + value);
|
|
}
|
|
}
|
|
writer.writeShort(0); // CRC will be filled below
|
|
final byte[] packet = writer.getBytes();
|
|
BinaryUtils.writeShort(packet, 0, packet.length);
|
|
BinaryUtils.writeShort(packet, packet.length - 2, ChecksumCalculator.computeCrc(packet, 0, packet.length - 2));
|
|
this.packet = packet;
|
|
}
|
|
}
|