mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-12-25 01:55: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;
|
||||
|
||||
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() {
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
package nodomain.freeyourgadget.gadgetbridge.service.devices.garmin;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@ -76,7 +78,7 @@ public class FileTransferHandler implements MessageHandler {
|
||||
// }
|
||||
|
||||
|
||||
class Download {
|
||||
public class Download {
|
||||
private FileFragment currentlyDownloading;
|
||||
|
||||
public FileFragment getCurrentlyDownloading() {
|
||||
@ -126,7 +128,7 @@ public class FileTransferHandler implements MessageHandler {
|
||||
outputFile.setLastModified(currentlyDownloading.directoryEntry.fileDate.getTime());
|
||||
|
||||
} catch (IOException e) {
|
||||
LOG.error("IOException: " + e);
|
||||
LOG.error("Failed to save file", e);
|
||||
}
|
||||
|
||||
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 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 int maxBlockSize = 500;
|
||||
private int dataSize;
|
||||
@ -290,7 +291,7 @@ public class FileTransferHandler implements MessageHandler {
|
||||
}
|
||||
}
|
||||
|
||||
class DirectoryEntry {
|
||||
public static class DirectoryEntry {
|
||||
private final int fileIndex;
|
||||
private final FileType.FILETYPE filetype;
|
||||
private final int fileNumber;
|
||||
@ -321,6 +322,7 @@ public class FileTransferHandler implements MessageHandler {
|
||||
return getFiletype().name() + "_" + getFileIndex() + (getFiletype().isFitFile() ? ".fit" : "");
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public String toString() {
|
||||
return "DirectoryEntry{" +
|
||||
|
@ -54,7 +54,6 @@ public class GarminByteBufferReader {
|
||||
public String readString() {
|
||||
final int size = readByte();
|
||||
byte[] bytes = new byte[size];
|
||||
if (byteBuffer.remaining() < size) throw new IllegalStateException();
|
||||
byteBuffer.get(bytes);
|
||||
return new String(bytes, StandardCharsets.UTF_8);
|
||||
}
|
||||
@ -62,7 +61,6 @@ public class GarminByteBufferReader {
|
||||
public byte[] readBytes(int size) {
|
||||
byte[] bytes = new byte[size];
|
||||
|
||||
if (byteBuffer.remaining() < size) throw new IllegalStateException();
|
||||
byteBuffer.get(bytes);
|
||||
|
||||
return bytes;
|
||||
|
@ -3,5 +3,5 @@ package nodomain.freeyourgadget.gadgetbridge.service.devices.garmin;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.garmin.messages.GFDIMessage;
|
||||
|
||||
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;
|
||||
|
||||
@ -292,7 +292,7 @@ public class NotificationsHandler implements MessageHandler {
|
||||
|
||||
}
|
||||
|
||||
class NotificationFragment {
|
||||
public static class NotificationFragment {
|
||||
private final int dataSize;
|
||||
private final ByteBuffer dataHolder;
|
||||
private final int maxBlockSize = 300;
|
||||
@ -330,5 +330,4 @@ public class NotificationsHandler implements MessageHandler {
|
||||
this.runningCrc = runningCrc;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
package nodomain.freeyourgadget.gadgetbridge.service.devices.garmin.fit;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@ -137,6 +139,7 @@ public class FitFile {
|
||||
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public String toString() {
|
||||
return dataRecords.toString();
|
||||
|
@ -1,5 +1,6 @@
|
||||
package nodomain.freeyourgadget.gadgetbridge.service.devices.garmin.fit;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
|
||||
@ -86,6 +87,8 @@ public class RecordHeader {
|
||||
return base;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Local Message: " + (null == localMessage ? "raw: " + rawLocalMessageType : "type: " + localMessage.name());
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package nodomain.freeyourgadget.gadgetbridge.service.devices.garmin.messages;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.bluetooth.BluetoothAdapter;
|
||||
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);
|
||||
}
|
||||
|
||||
@SuppressLint("MissingPermission")
|
||||
@Override
|
||||
protected boolean generateOutgoing() {
|
||||
|
||||
final int protocolFlags = this.incomingProtocolVersion / 100 == 1 ? 1 : 0;
|
||||
|
||||
final MessageWriter writer = new MessageWriter(response);
|
||||
@ -67,7 +68,14 @@ public class DeviceInformationMessage extends GFDIMessage {
|
||||
writer.writeInt(ourUnitNumber);
|
||||
writer.writeShort(ourSoftwareVersion);
|
||||
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.DEVICE);
|
||||
writer.writeByte(protocolFlags);
|
||||
@ -75,8 +83,17 @@ public class DeviceInformationMessage extends GFDIMessage {
|
||||
}
|
||||
|
||||
public GBDeviceEventVersionInfo getGBDeviceEvent() {
|
||||
|
||||
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);
|
||||
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
|
||||
);
|
||||
|
||||
GBDeviceEventVersionInfo versionCmd = new GBDeviceEventVersionInfo();
|
||||
versionCmd.fwVersion = getSoftwareVersionStr();
|
||||
|
@ -1,6 +1,5 @@
|
||||
package nodomain.freeyourgadget.gadgetbridge.service.devices.garmin.messages;
|
||||
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEvent;
|
||||
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.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.RecordHeader;
|
||||
|
||||
@ -20,14 +21,19 @@ public class FitDataMessage extends GFDIMessage {
|
||||
}
|
||||
|
||||
public static FitDataMessage parseIncoming(MessageReader reader, GarminMessage garminMessage) {
|
||||
List<RecordData> recordDataList = new ArrayList<>();
|
||||
|
||||
final List<RecordData> recordDataList = new ArrayList<>();
|
||||
|
||||
while (reader.remaining() > 0) {
|
||||
RecordHeader recordHeader = new RecordHeader((byte) reader.readByte());
|
||||
if (recordHeader.isDefinition())
|
||||
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);
|
||||
recordDataList.add(recordData);
|
||||
}
|
||||
@ -49,5 +55,4 @@ public class FitDataMessage extends GFDIMessage {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -150,6 +150,7 @@ public abstract class GFDIMessage {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
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;
|
||||
|
||||
|
@ -34,7 +34,7 @@ public class MusicControlCapabilitiesMessage extends GFDIMessage {
|
||||
return true;
|
||||
}
|
||||
|
||||
enum GarminMusicControlCommand {
|
||||
public enum GarminMusicControlCommand {
|
||||
TOGGLE_PLAY_PAUSE,
|
||||
SKIP_TO_NEXT_ITEM,
|
||||
SKIP_TO_PREVIOUS_ITEM,
|
||||
|
@ -1,6 +1,5 @@
|
||||
package nodomain.freeyourgadget.gadgetbridge.service.devices.garmin.messages.status;
|
||||
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.garmin.FileType;
|
||||
|
||||
public class CreateFileStatusMessage extends GFDIStatusMessage {
|
||||
@ -31,7 +30,7 @@ public class CreateFileStatusMessage extends GFDIStatusMessage {
|
||||
final int subType = reader.readByte();
|
||||
final FileType.FILETYPE filetype = FileType.FILETYPE.fromDataTypeSubType(dataType, subType);
|
||||
final int fileNumber = reader.readShort();
|
||||
if (!createStatus.equals(CreateStatus.OK)) {
|
||||
if (!CreateStatus.OK.equals(createStatus)) {
|
||||
LOG.warn("Received {} / {} for message {}", status, createStatus, garminMessage);
|
||||
} else {
|
||||
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);
|
||||
}
|
||||
|
||||
enum CreateStatus {
|
||||
public enum CreateStatus {
|
||||
OK,
|
||||
DUPLICATE,
|
||||
NO_SPACE,
|
||||
|
@ -1,6 +1,5 @@
|
||||
package nodomain.freeyourgadget.gadgetbridge.service.devices.garmin.messages.status;
|
||||
|
||||
|
||||
public class DownloadRequestStatusMessage extends GFDIStatusMessage {
|
||||
private final Status status;
|
||||
private final DownloadStatus downloadStatus;
|
||||
@ -22,7 +21,7 @@ public class DownloadRequestStatusMessage extends GFDIStatusMessage {
|
||||
final DownloadStatus downloadStatus = DownloadStatus.fromId(reader.readByte());
|
||||
final int maxFileSize = reader.readInt();
|
||||
|
||||
if (!downloadStatus.equals(DownloadStatus.OK)) {
|
||||
if (!DownloadStatus.OK.equals(downloadStatus)) {
|
||||
LOG.warn("Received {} / {} for message {}", status, downloadStatus, garminMessage);
|
||||
} else {
|
||||
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);
|
||||
}
|
||||
|
||||
enum DownloadStatus { //was DownloadRequestResponseMessage
|
||||
public enum DownloadStatus { //was DownloadRequestResponseMessage
|
||||
OK,
|
||||
INDEX_UNKNOWN,
|
||||
INDEX_NOT_READABLE,
|
||||
|
@ -1,6 +1,5 @@
|
||||
package nodomain.freeyourgadget.gadgetbridge.service.devices.garmin.messages.status;
|
||||
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.garmin.messages.MessageWriter;
|
||||
|
||||
public class FileTransferDataStatusMessage extends GFDIStatusMessage {
|
||||
@ -30,7 +29,7 @@ public class FileTransferDataStatusMessage extends GFDIStatusMessage {
|
||||
final TransferStatus transferStatus = TransferStatus.fromId(reader.readByte());
|
||||
final int dataOffset = reader.readInt();
|
||||
|
||||
if (!transferStatus.equals(TransferStatus.OK)) {
|
||||
if (!TransferStatus.OK.equals(transferStatus)) {
|
||||
LOG.warn("Received {} / {} for message {}", status, transferStatus, garminMessage);
|
||||
} else {
|
||||
LOG.info("Received {} / {} for message {}", status, transferStatus, garminMessage);
|
||||
|
@ -7,7 +7,6 @@ public class FitDataStatusMessage extends GFDIStatusMessage {
|
||||
private final Status status;
|
||||
private final FitDataStatusCode fitDataStatusCode;
|
||||
|
||||
|
||||
public FitDataStatusMessage(GarminMessage garminMessage, Status status, FitDataStatusCode fitDataStatusCode) {
|
||||
this.garminMessage = garminMessage;
|
||||
this.status = status;
|
||||
@ -23,8 +22,12 @@ public class FitDataStatusMessage extends GFDIStatusMessage {
|
||||
|
||||
public static FitDataStatusMessage parseIncoming(MessageReader reader, GarminMessage garminMessage) {
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -22,8 +22,12 @@ public class FitDefinitionStatusMessage extends GFDIStatusMessage {
|
||||
|
||||
public static FitDefinitionStatusMessage parseIncoming(MessageReader reader, GarminMessage garminMessage) {
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -9,6 +9,7 @@ public abstract class GFDIStatusMessage extends GFDIMessage {
|
||||
public static GFDIStatusMessage parseIncoming(MessageReader reader, GarminMessage garminMessage) {
|
||||
int originalMessageType = reader.readShort();
|
||||
final GarminMessage originalGarminMessage = GFDIMessage.GarminMessage.fromId(originalMessageType);
|
||||
|
||||
if (GarminMessage.PROTOBUF_REQUEST.equals(originalGarminMessage) || GarminMessage.PROTOBUF_RESPONSE.equals(originalGarminMessage)) {
|
||||
return ProtobufStatusMessage.parseIncoming(reader, originalGarminMessage);
|
||||
} else if (GarminMessage.NOTIFICATION_DATA.equals(originalGarminMessage)) {
|
||||
@ -23,7 +24,7 @@ public abstract class GFDIStatusMessage extends GFDIMessage {
|
||||
return CreateFileStatusMessage.parseIncoming(reader, originalGarminMessage);
|
||||
} else if (GarminMessage.SUPPORTED_FILE_TYPES_REQUEST.equals(originalGarminMessage)) {
|
||||
SupportedFileTypesStatusMessage supportedFileTypesStatusMessage = SupportedFileTypesStatusMessage.parseIncoming(reader, garminMessage);
|
||||
LOG.info(supportedFileTypesStatusMessage.toString());
|
||||
LOG.info("{}", supportedFileTypesStatusMessage);
|
||||
return supportedFileTypesStatusMessage;
|
||||
} else if (GarminMessage.FIT_DEFINITION.equals(originalGarminMessage)) {
|
||||
return FitDefinitionStatusMessage.parseIncoming(reader, originalGarminMessage);
|
||||
@ -33,7 +34,7 @@ public abstract class GFDIStatusMessage extends GFDIMessage {
|
||||
final Status status = Status.fromCode(reader.readByte());
|
||||
|
||||
if (Status.ACK == status) {
|
||||
LOG.info("Received ACK for message {}", originalGarminMessage.name());
|
||||
LOG.info("Received ACK for message {}", originalGarminMessage);
|
||||
} else {
|
||||
LOG.warn("Received {} for message {}", status, (null == originalGarminMessage) ? originalMessageType : originalGarminMessage.name());
|
||||
}
|
||||
@ -50,5 +51,4 @@ public abstract class GFDIStatusMessage extends GFDIMessage {
|
||||
protected Status getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,6 +1,5 @@
|
||||
package nodomain.freeyourgadget.gadgetbridge.service.devices.garmin.messages.status;
|
||||
|
||||
|
||||
public class NotificationDataStatusMessage extends GFDIStatusMessage {
|
||||
private final Status status;
|
||||
private final TransferStatus transferStatus;
|
||||
@ -19,7 +18,7 @@ public class NotificationDataStatusMessage extends GFDIStatusMessage {
|
||||
}
|
||||
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);
|
||||
} else {
|
||||
LOG.info("Received {} / {} for message {}", status, transferStatus, garminMessage);
|
||||
|
@ -1,6 +1,5 @@
|
||||
package nodomain.freeyourgadget.gadgetbridge.service.devices.garmin.messages.status;
|
||||
|
||||
|
||||
public class UploadRequestStatusMessage extends GFDIStatusMessage {
|
||||
private final Status status;
|
||||
private final UploadStatus uploadStatus;
|
||||
@ -28,7 +27,7 @@ public class UploadRequestStatusMessage extends GFDIStatusMessage {
|
||||
final int maxFileSize = reader.readInt();
|
||||
final int crcSeed = reader.readShort();
|
||||
|
||||
if (!uploadStatus.equals(UploadStatus.OK)) {
|
||||
if (!UploadStatus.OK.equals(uploadStatus)) {
|
||||
LOG.warn("Received {} / {} for message {}", status, uploadStatus, garminMessage);
|
||||
} else {
|
||||
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);
|
||||
}
|
||||
|
||||
enum UploadStatus {
|
||||
public enum UploadStatus {
|
||||
OK,
|
||||
INDEX_UNKNOWN,
|
||||
INDEX_NOT_WRITEABLE,
|
||||
|
Loading…
Reference in New Issue
Block a user