mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-12-26 02:25:50 +01:00
Garmin protocol: Fix linter warnings
This commit is contained in:
parent
72de9bafe9
commit
fb06a48756
@ -19,7 +19,10 @@ package nodomain.freeyourgadget.gadgetbridge.service.devices.garmin;
|
|||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
|
|
||||||
public final class ChecksumCalculator {
|
public final class ChecksumCalculator {
|
||||||
private static final int[] CONSTANTS = {0x0000, 0xCC01, 0xD801, 0x1400, 0xF001, 0x3C00, 0x2800, 0xE401, 0xA001, 0x6C00, 0x7800, 0xB401, 0x5000, 0x9C01, 0x8801, 0x4400};
|
private static final int[] CONSTANTS = {
|
||||||
|
0x0000, 0xCC01, 0xD801, 0x1400, 0xF001, 0x3C00, 0x2800, 0xE401,
|
||||||
|
0xA001, 0x6C00,0x7800, 0xB401, 0x5000, 0x9C01, 0x8801, 0x4400
|
||||||
|
};
|
||||||
|
|
||||||
private ChecksumCalculator() {
|
private ChecksumCalculator() {
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package nodomain.freeyourgadget.gadgetbridge.service.devices.garmin;
|
package nodomain.freeyourgadget.gadgetbridge.service.devices.garmin;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
@ -76,7 +78,7 @@ public class FileTransferHandler implements MessageHandler {
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
|
|
||||||
class Download {
|
public class Download {
|
||||||
private FileFragment currentlyDownloading;
|
private FileFragment currentlyDownloading;
|
||||||
|
|
||||||
public FileFragment getCurrentlyDownloading() {
|
public FileFragment getCurrentlyDownloading() {
|
||||||
@ -126,7 +128,7 @@ public class FileTransferHandler implements MessageHandler {
|
|||||||
outputFile.setLastModified(currentlyDownloading.directoryEntry.fileDate.getTime());
|
outputFile.setLastModified(currentlyDownloading.directoryEntry.fileDate.getTime());
|
||||||
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
LOG.error("IOException: " + e);
|
LOG.error("Failed to save file", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
LOG.debug("FILE DOWNLOAD COMPLETE {}", currentlyDownloading.getFileName());
|
LOG.debug("FILE DOWNLOAD COMPLETE {}", currentlyDownloading.getFileName());
|
||||||
@ -156,8 +158,7 @@ public class FileTransferHandler implements MessageHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Upload {
|
public static class Upload {
|
||||||
|
|
||||||
private FileFragment currentlyUploading;
|
private FileFragment currentlyUploading;
|
||||||
|
|
||||||
private UploadRequestMessage setCreateFileStatusMessage(CreateFileStatusMessage createFileStatusMessage) {
|
private UploadRequestMessage setCreateFileStatusMessage(CreateFileStatusMessage createFileStatusMessage) {
|
||||||
@ -216,7 +217,7 @@ public class FileTransferHandler implements MessageHandler {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class FileFragment {
|
public static class FileFragment {
|
||||||
private final DirectoryEntry directoryEntry;
|
private final DirectoryEntry directoryEntry;
|
||||||
private final int maxBlockSize = 500;
|
private final int maxBlockSize = 500;
|
||||||
private int dataSize;
|
private int dataSize;
|
||||||
@ -290,7 +291,7 @@ public class FileTransferHandler implements MessageHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class DirectoryEntry {
|
public static class DirectoryEntry {
|
||||||
private final int fileIndex;
|
private final int fileIndex;
|
||||||
private final FileType.FILETYPE filetype;
|
private final FileType.FILETYPE filetype;
|
||||||
private final int fileNumber;
|
private final int fileNumber;
|
||||||
@ -321,6 +322,7 @@ public class FileTransferHandler implements MessageHandler {
|
|||||||
return getFiletype().name() + "_" + getFileIndex() + (getFiletype().isFitFile() ? ".fit" : "");
|
return getFiletype().name() + "_" + getFileIndex() + (getFiletype().isFitFile() ? ".fit" : "");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "DirectoryEntry{" +
|
return "DirectoryEntry{" +
|
||||||
|
@ -54,7 +54,6 @@ public class GarminByteBufferReader {
|
|||||||
public String readString() {
|
public String readString() {
|
||||||
final int size = readByte();
|
final int size = readByte();
|
||||||
byte[] bytes = new byte[size];
|
byte[] bytes = new byte[size];
|
||||||
if (byteBuffer.remaining() < size) throw new IllegalStateException();
|
|
||||||
byteBuffer.get(bytes);
|
byteBuffer.get(bytes);
|
||||||
return new String(bytes, StandardCharsets.UTF_8);
|
return new String(bytes, StandardCharsets.UTF_8);
|
||||||
}
|
}
|
||||||
@ -62,7 +61,6 @@ public class GarminByteBufferReader {
|
|||||||
public byte[] readBytes(int size) {
|
public byte[] readBytes(int size) {
|
||||||
byte[] bytes = new byte[size];
|
byte[] bytes = new byte[size];
|
||||||
|
|
||||||
if (byteBuffer.remaining() < size) throw new IllegalStateException();
|
|
||||||
byteBuffer.get(bytes);
|
byteBuffer.get(bytes);
|
||||||
|
|
||||||
return bytes;
|
return bytes;
|
||||||
|
@ -3,5 +3,5 @@ package nodomain.freeyourgadget.gadgetbridge.service.devices.garmin;
|
|||||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.garmin.messages.GFDIMessage;
|
import nodomain.freeyourgadget.gadgetbridge.service.devices.garmin.messages.GFDIMessage;
|
||||||
|
|
||||||
public interface MessageHandler {
|
public interface MessageHandler {
|
||||||
public GFDIMessage handle(GFDIMessage message);
|
GFDIMessage handle(GFDIMessage message);
|
||||||
}
|
}
|
||||||
|
@ -262,7 +262,7 @@ public class NotificationsHandler implements MessageHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Upload {
|
public static class Upload {
|
||||||
|
|
||||||
private NotificationFragment currentlyUploading;
|
private NotificationFragment currentlyUploading;
|
||||||
|
|
||||||
@ -292,7 +292,7 @@ public class NotificationsHandler implements MessageHandler {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class NotificationFragment {
|
public static class NotificationFragment {
|
||||||
private final int dataSize;
|
private final int dataSize;
|
||||||
private final ByteBuffer dataHolder;
|
private final ByteBuffer dataHolder;
|
||||||
private final int maxBlockSize = 300;
|
private final int maxBlockSize = 300;
|
||||||
@ -330,5 +330,4 @@ public class NotificationsHandler implements MessageHandler {
|
|||||||
this.runningCrc = runningCrc;
|
this.runningCrc = runningCrc;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package nodomain.freeyourgadget.gadgetbridge.service.devices.garmin.fit;
|
package nodomain.freeyourgadget.gadgetbridge.service.devices.garmin.fit;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
@ -137,6 +139,7 @@ public class FitFile {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return dataRecords.toString();
|
return dataRecords.toString();
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package nodomain.freeyourgadget.gadgetbridge.service.devices.garmin.fit;
|
package nodomain.freeyourgadget.gadgetbridge.service.devices.garmin.fit;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
|
|
||||||
|
|
||||||
@ -86,6 +87,8 @@ public class RecordHeader {
|
|||||||
return base;
|
return base;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "Local Message: " + (null == localMessage ? "raw: " + rawLocalMessageType : "type: " + localMessage.name());
|
return "Local Message: " + (null == localMessage ? "raw: " + rawLocalMessageType : "type: " + localMessage.name());
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package nodomain.freeyourgadget.gadgetbridge.service.devices.garmin.messages;
|
package nodomain.freeyourgadget.gadgetbridge.service.devices.garmin.messages;
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint;
|
||||||
import android.bluetooth.BluetoothAdapter;
|
import android.bluetooth.BluetoothAdapter;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
|
|
||||||
@ -52,9 +53,9 @@ public class DeviceInformationMessage extends GFDIMessage {
|
|||||||
return new DeviceInformationMessage(garminMessage, protocolVersion, productNumber, unitNumber, softwareVersion, maxPacketSize, bluetoothFriendlyName, deviceName, deviceModel);
|
return new DeviceInformationMessage(garminMessage, protocolVersion, productNumber, unitNumber, softwareVersion, maxPacketSize, bluetoothFriendlyName, deviceName, deviceModel);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressLint("MissingPermission")
|
||||||
@Override
|
@Override
|
||||||
protected boolean generateOutgoing() {
|
protected boolean generateOutgoing() {
|
||||||
|
|
||||||
final int protocolFlags = this.incomingProtocolVersion / 100 == 1 ? 1 : 0;
|
final int protocolFlags = this.incomingProtocolVersion / 100 == 1 ? 1 : 0;
|
||||||
|
|
||||||
final MessageWriter writer = new MessageWriter(response);
|
final MessageWriter writer = new MessageWriter(response);
|
||||||
@ -67,7 +68,14 @@ public class DeviceInformationMessage extends GFDIMessage {
|
|||||||
writer.writeInt(ourUnitNumber);
|
writer.writeInt(ourUnitNumber);
|
||||||
writer.writeShort(ourSoftwareVersion);
|
writer.writeShort(ourSoftwareVersion);
|
||||||
writer.writeShort(ourMaxPacketSize);
|
writer.writeShort(ourMaxPacketSize);
|
||||||
writer.writeString(BluetoothAdapter.getDefaultAdapter().getName());
|
String bluetoothName;
|
||||||
|
try {
|
||||||
|
bluetoothName = BluetoothAdapter.getDefaultAdapter().getName();
|
||||||
|
} catch (final Exception e) {
|
||||||
|
LOG.error("Failed to get bluetooth name", e);
|
||||||
|
bluetoothName = "Unknown";
|
||||||
|
}
|
||||||
|
writer.writeString(bluetoothName);
|
||||||
writer.writeString(Build.MANUFACTURER);
|
writer.writeString(Build.MANUFACTURER);
|
||||||
writer.writeString(Build.DEVICE);
|
writer.writeString(Build.DEVICE);
|
||||||
writer.writeByte(protocolFlags);
|
writer.writeByte(protocolFlags);
|
||||||
@ -75,8 +83,17 @@ public class DeviceInformationMessage extends GFDIMessage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public GBDeviceEventVersionInfo getGBDeviceEvent() {
|
public GBDeviceEventVersionInfo getGBDeviceEvent() {
|
||||||
|
LOG.info(
|
||||||
LOG.info("Received device information: protocol {}, product {}, unit {}, SW {}, max packet {}, BT name {}, device name {}, device model {}", incomingProtocolVersion, incomingProductNumber, incomingUnitNumber, getSoftwareVersionStr(), incomingMaxPacketSize, bluetoothFriendlyName, deviceName, deviceModel);
|
"Received device information: protocol {}, product {}, unit {}, SW {}, max packet {}, BT name {}, device name {}, device model {}",
|
||||||
|
incomingProtocolVersion,
|
||||||
|
incomingProductNumber,
|
||||||
|
incomingUnitNumber,
|
||||||
|
getSoftwareVersionStr(),
|
||||||
|
incomingMaxPacketSize,
|
||||||
|
bluetoothFriendlyName,
|
||||||
|
deviceName,
|
||||||
|
deviceModel
|
||||||
|
);
|
||||||
|
|
||||||
GBDeviceEventVersionInfo versionCmd = new GBDeviceEventVersionInfo();
|
GBDeviceEventVersionInfo versionCmd = new GBDeviceEventVersionInfo();
|
||||||
versionCmd.fwVersion = getSoftwareVersionStr();
|
versionCmd.fwVersion = getSoftwareVersionStr();
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package nodomain.freeyourgadget.gadgetbridge.service.devices.garmin.messages;
|
package nodomain.freeyourgadget.gadgetbridge.service.devices.garmin.messages;
|
||||||
|
|
||||||
|
|
||||||
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEvent;
|
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEvent;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventFindPhone;
|
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventFindPhone;
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@ package nodomain.freeyourgadget.gadgetbridge.service.devices.garmin.messages;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.service.devices.garmin.fit.LocalMessage;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.garmin.fit.RecordData;
|
import nodomain.freeyourgadget.gadgetbridge.service.devices.garmin.fit.RecordData;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.garmin.fit.RecordHeader;
|
import nodomain.freeyourgadget.gadgetbridge.service.devices.garmin.fit.RecordHeader;
|
||||||
|
|
||||||
@ -20,14 +21,19 @@ public class FitDataMessage extends GFDIMessage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static FitDataMessage parseIncoming(MessageReader reader, GarminMessage garminMessage) {
|
public static FitDataMessage parseIncoming(MessageReader reader, GarminMessage garminMessage) {
|
||||||
List<RecordData> recordDataList = new ArrayList<>();
|
final List<RecordData> recordDataList = new ArrayList<>();
|
||||||
|
|
||||||
|
|
||||||
while (reader.remaining() > 0) {
|
while (reader.remaining() > 0) {
|
||||||
RecordHeader recordHeader = new RecordHeader((byte) reader.readByte());
|
RecordHeader recordHeader = new RecordHeader((byte) reader.readByte());
|
||||||
if (recordHeader.isDefinition())
|
if (recordHeader.isDefinition())
|
||||||
return null;
|
return null;
|
||||||
RecordData recordData = new RecordData(recordHeader.getLocalMessage().getRecordDefinition());
|
LocalMessage localMessage = recordHeader.getLocalMessage();
|
||||||
|
if (localMessage == null) {
|
||||||
|
LOG.warn("Local message is null");
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
RecordData recordData = new RecordData(localMessage.getRecordDefinition());
|
||||||
recordData.parseDataMessage(reader);
|
recordData.parseDataMessage(reader);
|
||||||
recordDataList.add(recordData);
|
recordDataList.add(recordData);
|
||||||
}
|
}
|
||||||
@ -49,5 +55,4 @@ public class FitDataMessage extends GFDIMessage {
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -150,6 +150,7 @@ public abstract class GFDIMessage {
|
|||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getId() {
|
public int getId() {
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
@ -178,7 +179,7 @@ public abstract class GFDIMessage {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static class MessageReader extends GarminByteBufferReader {
|
public static class MessageReader extends GarminByteBufferReader {
|
||||||
|
|
||||||
private final int payloadSize;
|
private final int payloadSize;
|
||||||
|
|
||||||
|
@ -34,7 +34,7 @@ public class MusicControlCapabilitiesMessage extends GFDIMessage {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
enum GarminMusicControlCommand {
|
public enum GarminMusicControlCommand {
|
||||||
TOGGLE_PLAY_PAUSE,
|
TOGGLE_PLAY_PAUSE,
|
||||||
SKIP_TO_NEXT_ITEM,
|
SKIP_TO_NEXT_ITEM,
|
||||||
SKIP_TO_PREVIOUS_ITEM,
|
SKIP_TO_PREVIOUS_ITEM,
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package nodomain.freeyourgadget.gadgetbridge.service.devices.garmin.messages.status;
|
package nodomain.freeyourgadget.gadgetbridge.service.devices.garmin.messages.status;
|
||||||
|
|
||||||
|
|
||||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.garmin.FileType;
|
import nodomain.freeyourgadget.gadgetbridge.service.devices.garmin.FileType;
|
||||||
|
|
||||||
public class CreateFileStatusMessage extends GFDIStatusMessage {
|
public class CreateFileStatusMessage extends GFDIStatusMessage {
|
||||||
@ -31,7 +30,7 @@ public class CreateFileStatusMessage extends GFDIStatusMessage {
|
|||||||
final int subType = reader.readByte();
|
final int subType = reader.readByte();
|
||||||
final FileType.FILETYPE filetype = FileType.FILETYPE.fromDataTypeSubType(dataType, subType);
|
final FileType.FILETYPE filetype = FileType.FILETYPE.fromDataTypeSubType(dataType, subType);
|
||||||
final int fileNumber = reader.readShort();
|
final int fileNumber = reader.readShort();
|
||||||
if (!createStatus.equals(CreateStatus.OK)) {
|
if (!CreateStatus.OK.equals(createStatus)) {
|
||||||
LOG.warn("Received {} / {} for message {}", status, createStatus, garminMessage);
|
LOG.warn("Received {} / {} for message {}", status, createStatus, garminMessage);
|
||||||
} else {
|
} else {
|
||||||
LOG.info("Received {} / {} for message {}", status, createStatus, garminMessage);
|
LOG.info("Received {} / {} for message {}", status, createStatus, garminMessage);
|
||||||
@ -51,7 +50,7 @@ public class CreateFileStatusMessage extends GFDIStatusMessage {
|
|||||||
return status.equals(Status.ACK) && createStatus.equals(CreateStatus.OK);
|
return status.equals(Status.ACK) && createStatus.equals(CreateStatus.OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
enum CreateStatus {
|
public enum CreateStatus {
|
||||||
OK,
|
OK,
|
||||||
DUPLICATE,
|
DUPLICATE,
|
||||||
NO_SPACE,
|
NO_SPACE,
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package nodomain.freeyourgadget.gadgetbridge.service.devices.garmin.messages.status;
|
package nodomain.freeyourgadget.gadgetbridge.service.devices.garmin.messages.status;
|
||||||
|
|
||||||
|
|
||||||
public class DownloadRequestStatusMessage extends GFDIStatusMessage {
|
public class DownloadRequestStatusMessage extends GFDIStatusMessage {
|
||||||
private final Status status;
|
private final Status status;
|
||||||
private final DownloadStatus downloadStatus;
|
private final DownloadStatus downloadStatus;
|
||||||
@ -22,7 +21,7 @@ public class DownloadRequestStatusMessage extends GFDIStatusMessage {
|
|||||||
final DownloadStatus downloadStatus = DownloadStatus.fromId(reader.readByte());
|
final DownloadStatus downloadStatus = DownloadStatus.fromId(reader.readByte());
|
||||||
final int maxFileSize = reader.readInt();
|
final int maxFileSize = reader.readInt();
|
||||||
|
|
||||||
if (!downloadStatus.equals(DownloadStatus.OK)) {
|
if (!DownloadStatus.OK.equals(downloadStatus)) {
|
||||||
LOG.warn("Received {} / {} for message {}", status, downloadStatus, garminMessage);
|
LOG.warn("Received {} / {} for message {}", status, downloadStatus, garminMessage);
|
||||||
} else {
|
} else {
|
||||||
LOG.info("Received {} / {} for message {}", status, downloadStatus, garminMessage);
|
LOG.info("Received {} / {} for message {}", status, downloadStatus, garminMessage);
|
||||||
@ -38,7 +37,7 @@ public class DownloadRequestStatusMessage extends GFDIStatusMessage {
|
|||||||
return status.equals(Status.ACK) && downloadStatus.equals(DownloadStatus.OK);
|
return status.equals(Status.ACK) && downloadStatus.equals(DownloadStatus.OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
enum DownloadStatus { //was DownloadRequestResponseMessage
|
public enum DownloadStatus { //was DownloadRequestResponseMessage
|
||||||
OK,
|
OK,
|
||||||
INDEX_UNKNOWN,
|
INDEX_UNKNOWN,
|
||||||
INDEX_NOT_READABLE,
|
INDEX_NOT_READABLE,
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package nodomain.freeyourgadget.gadgetbridge.service.devices.garmin.messages.status;
|
package nodomain.freeyourgadget.gadgetbridge.service.devices.garmin.messages.status;
|
||||||
|
|
||||||
|
|
||||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.garmin.messages.MessageWriter;
|
import nodomain.freeyourgadget.gadgetbridge.service.devices.garmin.messages.MessageWriter;
|
||||||
|
|
||||||
public class FileTransferDataStatusMessage extends GFDIStatusMessage {
|
public class FileTransferDataStatusMessage extends GFDIStatusMessage {
|
||||||
@ -30,7 +29,7 @@ public class FileTransferDataStatusMessage extends GFDIStatusMessage {
|
|||||||
final TransferStatus transferStatus = TransferStatus.fromId(reader.readByte());
|
final TransferStatus transferStatus = TransferStatus.fromId(reader.readByte());
|
||||||
final int dataOffset = reader.readInt();
|
final int dataOffset = reader.readInt();
|
||||||
|
|
||||||
if (!transferStatus.equals(TransferStatus.OK)) {
|
if (!TransferStatus.OK.equals(transferStatus)) {
|
||||||
LOG.warn("Received {} / {} for message {}", status, transferStatus, garminMessage);
|
LOG.warn("Received {} / {} for message {}", status, transferStatus, garminMessage);
|
||||||
} else {
|
} else {
|
||||||
LOG.info("Received {} / {} for message {}", status, transferStatus, garminMessage);
|
LOG.info("Received {} / {} for message {}", status, transferStatus, garminMessage);
|
||||||
|
@ -7,7 +7,6 @@ public class FitDataStatusMessage extends GFDIStatusMessage {
|
|||||||
private final Status status;
|
private final Status status;
|
||||||
private final FitDataStatusCode fitDataStatusCode;
|
private final FitDataStatusCode fitDataStatusCode;
|
||||||
|
|
||||||
|
|
||||||
public FitDataStatusMessage(GarminMessage garminMessage, Status status, FitDataStatusCode fitDataStatusCode) {
|
public FitDataStatusMessage(GarminMessage garminMessage, Status status, FitDataStatusCode fitDataStatusCode) {
|
||||||
this.garminMessage = garminMessage;
|
this.garminMessage = garminMessage;
|
||||||
this.status = status;
|
this.status = status;
|
||||||
@ -23,8 +22,12 @@ public class FitDataStatusMessage extends GFDIStatusMessage {
|
|||||||
|
|
||||||
public static FitDataStatusMessage parseIncoming(MessageReader reader, GarminMessage garminMessage) {
|
public static FitDataStatusMessage parseIncoming(MessageReader reader, GarminMessage garminMessage) {
|
||||||
final Status status = Status.fromCode(reader.readByte());
|
final Status status = Status.fromCode(reader.readByte());
|
||||||
final FitDataStatusCode fitDataStatusCode = FitDataStatusCode.fromCode(reader.readByte());
|
final int fitDataStatusCodeByte = reader.readByte();
|
||||||
|
final FitDataStatusCode fitDataStatusCode = FitDataStatusCode.fromCode(fitDataStatusCodeByte);
|
||||||
|
if (fitDataStatusCode == null) {
|
||||||
|
LOG.warn("Unknown fit data status code {}", fitDataStatusCodeByte);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
return new FitDataStatusMessage(garminMessage, status, fitDataStatusCode);
|
return new FitDataStatusMessage(garminMessage, status, fitDataStatusCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,8 +22,12 @@ public class FitDefinitionStatusMessage extends GFDIStatusMessage {
|
|||||||
|
|
||||||
public static FitDefinitionStatusMessage parseIncoming(MessageReader reader, GarminMessage garminMessage) {
|
public static FitDefinitionStatusMessage parseIncoming(MessageReader reader, GarminMessage garminMessage) {
|
||||||
final Status status = Status.fromCode(reader.readByte());
|
final Status status = Status.fromCode(reader.readByte());
|
||||||
final FitDefinitionStatusCode fitDefinitionStatusCode = FitDefinitionStatusCode.fromCode(reader.readByte());
|
final int fitDefinitionStatusCodeByte = reader.readByte();
|
||||||
|
final FitDefinitionStatusCode fitDefinitionStatusCode = FitDefinitionStatusCode.fromCode(fitDefinitionStatusCodeByte);
|
||||||
|
if (fitDefinitionStatusCode == null) {
|
||||||
|
LOG.warn("Unknown fit definition status code {}", fitDefinitionStatusCodeByte);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
return new FitDefinitionStatusMessage(garminMessage, status, fitDefinitionStatusCode);
|
return new FitDefinitionStatusMessage(garminMessage, status, fitDefinitionStatusCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,6 +9,7 @@ public abstract class GFDIStatusMessage extends GFDIMessage {
|
|||||||
public static GFDIStatusMessage parseIncoming(MessageReader reader, GarminMessage garminMessage) {
|
public static GFDIStatusMessage parseIncoming(MessageReader reader, GarminMessage garminMessage) {
|
||||||
int originalMessageType = reader.readShort();
|
int originalMessageType = reader.readShort();
|
||||||
final GarminMessage originalGarminMessage = GFDIMessage.GarminMessage.fromId(originalMessageType);
|
final GarminMessage originalGarminMessage = GFDIMessage.GarminMessage.fromId(originalMessageType);
|
||||||
|
|
||||||
if (GarminMessage.PROTOBUF_REQUEST.equals(originalGarminMessage) || GarminMessage.PROTOBUF_RESPONSE.equals(originalGarminMessage)) {
|
if (GarminMessage.PROTOBUF_REQUEST.equals(originalGarminMessage) || GarminMessage.PROTOBUF_RESPONSE.equals(originalGarminMessage)) {
|
||||||
return ProtobufStatusMessage.parseIncoming(reader, originalGarminMessage);
|
return ProtobufStatusMessage.parseIncoming(reader, originalGarminMessage);
|
||||||
} else if (GarminMessage.NOTIFICATION_DATA.equals(originalGarminMessage)) {
|
} else if (GarminMessage.NOTIFICATION_DATA.equals(originalGarminMessage)) {
|
||||||
@ -23,7 +24,7 @@ public abstract class GFDIStatusMessage extends GFDIMessage {
|
|||||||
return CreateFileStatusMessage.parseIncoming(reader, originalGarminMessage);
|
return CreateFileStatusMessage.parseIncoming(reader, originalGarminMessage);
|
||||||
} else if (GarminMessage.SUPPORTED_FILE_TYPES_REQUEST.equals(originalGarminMessage)) {
|
} else if (GarminMessage.SUPPORTED_FILE_TYPES_REQUEST.equals(originalGarminMessage)) {
|
||||||
SupportedFileTypesStatusMessage supportedFileTypesStatusMessage = SupportedFileTypesStatusMessage.parseIncoming(reader, garminMessage);
|
SupportedFileTypesStatusMessage supportedFileTypesStatusMessage = SupportedFileTypesStatusMessage.parseIncoming(reader, garminMessage);
|
||||||
LOG.info(supportedFileTypesStatusMessage.toString());
|
LOG.info("{}", supportedFileTypesStatusMessage);
|
||||||
return supportedFileTypesStatusMessage;
|
return supportedFileTypesStatusMessage;
|
||||||
} else if (GarminMessage.FIT_DEFINITION.equals(originalGarminMessage)) {
|
} else if (GarminMessage.FIT_DEFINITION.equals(originalGarminMessage)) {
|
||||||
return FitDefinitionStatusMessage.parseIncoming(reader, originalGarminMessage);
|
return FitDefinitionStatusMessage.parseIncoming(reader, originalGarminMessage);
|
||||||
@ -33,7 +34,7 @@ public abstract class GFDIStatusMessage extends GFDIMessage {
|
|||||||
final Status status = Status.fromCode(reader.readByte());
|
final Status status = Status.fromCode(reader.readByte());
|
||||||
|
|
||||||
if (Status.ACK == status) {
|
if (Status.ACK == status) {
|
||||||
LOG.info("Received ACK for message {}", originalGarminMessage.name());
|
LOG.info("Received ACK for message {}", originalGarminMessage);
|
||||||
} else {
|
} else {
|
||||||
LOG.warn("Received {} for message {}", status, (null == originalGarminMessage) ? originalMessageType : originalGarminMessage.name());
|
LOG.warn("Received {} for message {}", status, (null == originalGarminMessage) ? originalMessageType : originalGarminMessage.name());
|
||||||
}
|
}
|
||||||
@ -50,5 +51,4 @@ public abstract class GFDIStatusMessage extends GFDIMessage {
|
|||||||
protected Status getStatus() {
|
protected Status getStatus() {
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package nodomain.freeyourgadget.gadgetbridge.service.devices.garmin.messages.status;
|
package nodomain.freeyourgadget.gadgetbridge.service.devices.garmin.messages.status;
|
||||||
|
|
||||||
|
|
||||||
public class NotificationDataStatusMessage extends GFDIStatusMessage {
|
public class NotificationDataStatusMessage extends GFDIStatusMessage {
|
||||||
private final Status status;
|
private final Status status;
|
||||||
private final TransferStatus transferStatus;
|
private final TransferStatus transferStatus;
|
||||||
@ -19,7 +18,7 @@ public class NotificationDataStatusMessage extends GFDIStatusMessage {
|
|||||||
}
|
}
|
||||||
final TransferStatus transferStatus = TransferStatus.fromId(reader.readByte());
|
final TransferStatus transferStatus = TransferStatus.fromId(reader.readByte());
|
||||||
|
|
||||||
if (!transferStatus.equals(TransferStatus.OK)) {
|
if (!TransferStatus.OK.equals(transferStatus)) {
|
||||||
LOG.warn("Received {} / {} for message {}", status, transferStatus, garminMessage);
|
LOG.warn("Received {} / {} for message {}", status, transferStatus, garminMessage);
|
||||||
} else {
|
} else {
|
||||||
LOG.info("Received {} / {} for message {}", status, transferStatus, garminMessage);
|
LOG.info("Received {} / {} for message {}", status, transferStatus, garminMessage);
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package nodomain.freeyourgadget.gadgetbridge.service.devices.garmin.messages.status;
|
package nodomain.freeyourgadget.gadgetbridge.service.devices.garmin.messages.status;
|
||||||
|
|
||||||
|
|
||||||
public class UploadRequestStatusMessage extends GFDIStatusMessage {
|
public class UploadRequestStatusMessage extends GFDIStatusMessage {
|
||||||
private final Status status;
|
private final Status status;
|
||||||
private final UploadStatus uploadStatus;
|
private final UploadStatus uploadStatus;
|
||||||
@ -28,7 +27,7 @@ public class UploadRequestStatusMessage extends GFDIStatusMessage {
|
|||||||
final int maxFileSize = reader.readInt();
|
final int maxFileSize = reader.readInt();
|
||||||
final int crcSeed = reader.readShort();
|
final int crcSeed = reader.readShort();
|
||||||
|
|
||||||
if (!uploadStatus.equals(UploadStatus.OK)) {
|
if (!UploadStatus.OK.equals(uploadStatus)) {
|
||||||
LOG.warn("Received {} / {} for message {}", status, uploadStatus, garminMessage);
|
LOG.warn("Received {} / {} for message {}", status, uploadStatus, garminMessage);
|
||||||
} else {
|
} else {
|
||||||
LOG.info("Received {} / {} for message {}", status, uploadStatus, garminMessage);
|
LOG.info("Received {} / {} for message {}", status, uploadStatus, garminMessage);
|
||||||
@ -48,7 +47,7 @@ public class UploadRequestStatusMessage extends GFDIStatusMessage {
|
|||||||
return status.equals(Status.ACK) && uploadStatus.equals(UploadStatus.OK);
|
return status.equals(Status.ACK) && uploadStatus.equals(UploadStatus.OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
enum UploadStatus {
|
public enum UploadStatus {
|
||||||
OK,
|
OK,
|
||||||
INDEX_UNKNOWN,
|
INDEX_UNKNOWN,
|
||||||
INDEX_NOT_WRITEABLE,
|
INDEX_NOT_WRITEABLE,
|
||||||
|
Loading…
Reference in New Issue
Block a user