diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/moyoung/AbstractMoyoungDeviceCoordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/moyoung/AbstractMoyoungDeviceCoordinator.java index 7cc59abc2..6fe272d6e 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/moyoung/AbstractMoyoungDeviceCoordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/moyoung/AbstractMoyoungDeviceCoordinator.java @@ -208,4 +208,8 @@ public abstract class AbstractMoyoungDeviceCoordinator extends AbstractDeviceCoo public MoyoungSetting[] getSupportedSettings() { return MOYOUNG_SETTINGS; } + + public int getMtu() { + return 20; + } } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/moyoung/ColmiI28UltraCoordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/moyoung/ColmiI28UltraCoordinator.java index 578d58063..3b9cb7778 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/moyoung/ColmiI28UltraCoordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/moyoung/ColmiI28UltraCoordinator.java @@ -55,4 +55,9 @@ public class ColmiI28UltraCoordinator extends AbstractMoyoungDeviceCoordinator { public String getManufacturer() { return "Colmi"; } + + @Override + public int getMtu() { + return 508; + } } \ No newline at end of file diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/moyoung/FetchDataOperation.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/moyoung/FetchDataOperation.java index bf0df61c5..b5216fe30 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/moyoung/FetchDataOperation.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/moyoung/FetchDataOperation.java @@ -57,13 +57,13 @@ public class FetchDataOperation extends AbstractBTLEOperation void sendSetting(TransactionBuilder builder, MoyoungSetting setting, T newValue) { - sendPacket(builder, MoyoungPacketOut.buildPacket(setting.cmdSet, setting.encode(newValue))); + sendPacket(builder, MoyoungPacketOut.buildPacket(mtu, setting.cmdSet, setting.encode(newValue))); } private void sendSetting(MoyoungSetting setting, T newValue) @@ -1146,7 +1152,7 @@ public class MoyoungDeviceSupport extends AbstractBTLEDeviceSupport { try { TransactionBuilder builder = performInitialized("querySetting"); - sendPacket(builder, MoyoungPacketOut.buildPacket(setting.cmdQuery, new byte[0])); + sendPacket(builder, MoyoungPacketOut.buildPacket(mtu, setting.cmdQuery, new byte[0])); builder.queue(getQueue()); queriedSettings.add(setting); } catch (IOException e) { @@ -1485,10 +1491,10 @@ public class MoyoungDeviceSupport extends AbstractBTLEDeviceSupport { packetWeatherToday.putShort(weatherToday.pm25); packetWeatherToday.put(weatherToday.lunar_or_festival.getBytes("unicodebigunmarked")); packetWeatherToday.put(weatherToday.city.getBytes("unicodebigunmarked")); - sendPacket(builder, MoyoungPacketOut.buildPacket(MoyoungConstants.CMD_SET_WEATHER_TODAY, packetWeatherToday.array())); + sendPacket(builder, MoyoungPacketOut.buildPacket(mtu, MoyoungConstants.CMD_SET_WEATHER_TODAY, packetWeatherToday.array())); - ByteBuffer packetWeatherForecast = ByteBuffer.allocate(6 * 3); - for(int i = 0; i < 6; i++) + ByteBuffer packetWeatherForecast = ByteBuffer.allocate(7 * 3); + for(int i = 0; i < 7; i++) { MoyoungWeatherForecast forecast; if (weatherSpec.forecasts.size() > i) @@ -1499,7 +1505,7 @@ public class MoyoungDeviceSupport extends AbstractBTLEDeviceSupport { packetWeatherForecast.put(forecast.minTemp); packetWeatherForecast.put(forecast.maxTemp); } - sendPacket(builder, MoyoungPacketOut.buildPacket(MoyoungConstants.CMD_SET_WEATHER_FUTURE, packetWeatherForecast.array())); + sendPacket(builder, MoyoungPacketOut.buildPacket(mtu, MoyoungConstants.CMD_SET_WEATHER_FUTURE, packetWeatherForecast.array())); builder.queue(getQueue()); } catch (IOException e) { diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/moyoung/MoyoungPacketOut.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/moyoung/MoyoungPacketOut.java index 18efef729..b570cbb7c 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/moyoung/MoyoungPacketOut.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/moyoung/MoyoungPacketOut.java @@ -59,12 +59,12 @@ public class MoyoungPacketOut extends MoyoungPacket { * @param payload The packet payload * @return The encoded packet */ - public static byte[] buildPacket(byte packetType, @NonNull byte[] payload) + public static byte[] buildPacket(int mtu, byte packetType, @NonNull byte[] payload) { byte[] packet = new byte[payload.length + 5]; packet[0] = (byte)0xFE; packet[1] = (byte)0xEA; - if (MoyoungDeviceSupport.MTU == 20) + if (mtu == 20) { packet[2] = 16; packet[3] = (byte)(packet.length & 0xFF); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/moyoung/QuerySettingsOperation.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/moyoung/QuerySettingsOperation.java index 02d15e868..ea670d448 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/moyoung/QuerySettingsOperation.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/moyoung/QuerySettingsOperation.java @@ -68,7 +68,7 @@ public class QuerySettingsOperation extends AbstractBTLEOperation