From d0b525f4205281c1b58cd46fbb7a7cb29aeba5ed Mon Sep 17 00:00:00 2001 From: Daniele Gobbetti Date: Tue, 20 Aug 2024 15:59:32 +0200 Subject: [PATCH] Garmin: minor fixes to some messages. Prevent sending double status messages / ACKs if the actual outgoing message is also a status message. Prevent sending ACKs for incoming ACK messages. --- .../garmin/messages/CurrentTimeRequestMessage.java | 2 +- .../messages/MusicControlCapabilitiesMessage.java | 2 +- .../garmin/messages/status/GFDIStatusMessage.java | 2 +- .../garmin/messages/status/GenericStatusMessage.java | 11 ++++++++++- .../status/NotificationDataStatusMessage.java | 5 ----- 5 files changed, 13 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/garmin/messages/CurrentTimeRequestMessage.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/garmin/messages/CurrentTimeRequestMessage.java index d263414c3..c54dfb06e 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/garmin/messages/CurrentTimeRequestMessage.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/garmin/messages/CurrentTimeRequestMessage.java @@ -15,7 +15,7 @@ public class CurrentTimeRequestMessage extends GFDIMessage { public CurrentTimeRequestMessage(int referenceID, GarminMessage garminMessage) { this.garminMessage = garminMessage; this.referenceID = referenceID; - this.statusMessage = this.getStatusMessage(); + this.statusMessage = null; //our outgoing message is an ACK message } public static CurrentTimeRequestMessage parseIncoming(MessageReader reader, GarminMessage garminMessage) { diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/garmin/messages/MusicControlCapabilitiesMessage.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/garmin/messages/MusicControlCapabilitiesMessage.java index 5963907c1..173229ea1 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/garmin/messages/MusicControlCapabilitiesMessage.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/garmin/messages/MusicControlCapabilitiesMessage.java @@ -8,7 +8,7 @@ public class MusicControlCapabilitiesMessage extends GFDIMessage { public MusicControlCapabilitiesMessage(GarminMessage garminMessage, int supportedCapabilities) { this.garminMessage = garminMessage; this.supportedCapabilities = supportedCapabilities; - this.statusMessage = this.getStatusMessage(); + this.statusMessage = null; //our outgoing message is an ACK message } public static MusicControlCapabilitiesMessage parseIncoming(MessageReader reader, GarminMessage garminMessage) { diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/garmin/messages/status/GFDIStatusMessage.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/garmin/messages/status/GFDIStatusMessage.java index fc39b76c9..4559dbbdb 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/garmin/messages/status/GFDIStatusMessage.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/garmin/messages/status/GFDIStatusMessage.java @@ -43,7 +43,7 @@ public abstract class GFDIStatusMessage extends GFDIMessage { LOG.warn("Received {} for message {}", status, (null == originalGarminMessage) ? originalMessageType : originalGarminMessage.name()); } - return new GenericStatusMessage(garminMessage, status); + return new GenericStatusMessage(originalGarminMessage, status, false); //don't ack the ack } } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/garmin/messages/status/GenericStatusMessage.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/garmin/messages/status/GenericStatusMessage.java index 95dad72f2..7df509cc5 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/garmin/messages/status/GenericStatusMessage.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/garmin/messages/status/GenericStatusMessage.java @@ -6,15 +6,24 @@ public class GenericStatusMessage extends GFDIStatusMessage { private final Status status; private int messageType; // for unsupported message types + private boolean sendOutgoing; public GenericStatusMessage(GarminMessage originalMessage, Status status) { this.garminMessage = originalMessage; this.status = status; + this.sendOutgoing = true; + } + + public GenericStatusMessage(GarminMessage originalMessage, Status status, boolean sendOutgoing) { + this.garminMessage = originalMessage; + this.status = status; + this.sendOutgoing = sendOutgoing; } public GenericStatusMessage(int messageType, Status status) { this.messageType = messageType; this.status = status; + this.sendOutgoing = false; } @Override @@ -24,7 +33,7 @@ public class GenericStatusMessage extends GFDIStatusMessage { writer.writeShort(GarminMessage.RESPONSE.getId()); writer.writeShort(messageType != 0 ? messageType : garminMessage.getId()); writer.writeByte(status.ordinal()); - return true; + return sendOutgoing; } } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/garmin/messages/status/NotificationDataStatusMessage.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/garmin/messages/status/NotificationDataStatusMessage.java index f0170d5fa..40c532a9a 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/garmin/messages/status/NotificationDataStatusMessage.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/garmin/messages/status/NotificationDataStatusMessage.java @@ -30,11 +30,6 @@ public class NotificationDataStatusMessage extends GFDIStatusMessage { return status.equals(Status.ACK) && transferStatus.equals(TransferStatus.OK); } - @Override - protected boolean generateOutgoing() { - return false; - } - public enum TransferStatus { OK, RESEND,