Garmin: Map all known files types

This commit is contained in:
José Rebelo 2024-04-21 20:13:07 +01:00
parent c58fea1a67
commit 919441cfa8
3 changed files with 41 additions and 5 deletions

View File

@ -12,6 +12,8 @@ import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;
import nodomain.freeyourgadget.gadgetbridge.service.devices.garmin.deviceevents.FileDownloadedDeviceEvent;
import nodomain.freeyourgadget.gadgetbridge.service.devices.garmin.messages.DownloadRequestMessage;
@ -31,6 +33,15 @@ public class FileTransferHandler implements MessageHandler {
private final Download download;
private final Upload upload;
private static final Set<FileType.FILETYPE> FILE_TYPES_TO_PROCESS = new HashSet<FileType.FILETYPE>() {{
add(FileType.FILETYPE.DIRECTORY);
add(FileType.FILETYPE.ACTIVITY);
add(FileType.FILETYPE.MONITOR);
add(FileType.FILETYPE.METRICS);
add(FileType.FILETYPE.CHANGELOG);
add(FileType.FILETYPE.SLEEP);
}};
public FileTransferHandler(GarminSupport deviceSupport) {
this.deviceSupport = deviceSupport;
this.download = new Download();
@ -156,6 +167,8 @@ public class FileTransferHandler implements MessageHandler {
final DirectoryEntry directoryEntry = new DirectoryEntry(fileIndex, filetype, fileNumber, specificFlags, fileFlags, fileSize, fileDate);
if (directoryEntry.filetype == null) //silently discard unsupported files
continue;
if (!FILE_TYPES_TO_PROCESS.contains(directoryEntry.filetype))
continue;
deviceSupport.addFileToDownloadList(directoryEntry);
}
currentlyDownloading = null;
@ -325,7 +338,7 @@ public class FileTransferHandler implements MessageHandler {
public String getFileName() {
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss");
String dateString = dateFormat.format(fileDate);
return getFiletype().name() + "_" + getFileIndex() + "_" + dateString + (getFiletype().isFitFile() ? ".fit" : "");
return getFiletype().name() + "_" + getFileIndex() + "_" + dateString + (getFiletype().isFitFile() ? ".fit" : ".bin");
}
@NonNull

View File

@ -35,15 +35,38 @@ public class FileType {
}
public enum FILETYPE { //TODO: add specialized method to parse each file type to the enum?
// virtual/undocumented
DIRECTORY(0, 0),
// fit files
ACTIVITY(128, 4),
WORKOUTS(128, 5),
SCHEDULES(128, 7),
LOCATION(128, 8),
TOTALS(128, 10),
GOALS(128, 11),
SUMMARY(128, 20),
RECORDS(128, 29),
MONITOR(128, 32),
CLUBS(128, 37),
SCORE(128, 38),
ADJUSTMENTS(128, 39),
CHANGELOG(128, 41),
METRICS(128, 44),
SLEEP(128, 49),
MUSCLE_MAP(128, 59),
ECG(128, 61),
BENCHMARK(128, 62),
HRV_STATUS(128, 68),
HSA(128, 70),
FBT_BACKUP(128, 72),
SKIN_TEMP(128, 73),
FBT_PTD_BACKUP(128, 74),
//"virtual" and/or undocumented file types
DIRECTORY(0, 0),
//SETTINGS(Pair.create(128,2)),
// Other files
ERROR_SHUTDOWN_REPORTS(255, 245),
IQ_ERROR_REPORTS(255, 244),
ULF_LOGS(255, 247),
;
private final int type;

View File

@ -33,7 +33,7 @@ public class SupportedFileTypesStatusMessage extends GFDIStatusMessage {
final String garminDeviceFileType = reader.readString();
FileType fileType = new FileType(fileDataType, fileSubType, garminDeviceFileType);
if (fileType.getFileType() == null) {
LOG.warn("Watch supports a filetype that we do not support: {}", garminDeviceFileType);
LOG.warn("Watch supports a filetype that we do not support: {}/{}: {}", fileDataType, fileSubType, garminDeviceFileType);
continue;
}
types.add(fileType);