mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge.git
synced 2026-07-31 07:44:24 +02:00
Garmin: fix .FIT file decoding for older Garmin devices
example files for testing: https://github.com/ThomasKuehne/FIT-test-files/tree/main/Activity/2016/Activity_20161021_005_000_Swimming_Fr230_77e3563673fbc2b19a60a78b6f5f6f49.fit https://github.com/ThomasKuehne/FIT-test-files/tree/main/Activity/2018/Activity_20180113_000_015_Elliptical_Fenix3Hr_51b4891a23b94b634b93c666e1417fea.fit https://github.com/ThomasKuehne/FIT-test-files/tree/main/Activity/2024/Activity_20240708_015_014_Rowing_Indoor-Rowing_Fr735xt_e358d81585941c7ac1dc747987d711bc.fit https://github.com/ThomasKuehne/FIT-test-files/tree/main/Activity/2025/Activity_20250128_011_000_Walking_Fr55_872d00f0d3b2a4251c86255dad477d93.fit
This commit is contained in:
+22
-1
@@ -174,7 +174,16 @@ public class RecordData {
|
||||
}
|
||||
|
||||
public <T> T getFieldByNumber(int number, final Class<T> clazz) {
|
||||
return safeCast(getFieldByNumber(number), clazz);
|
||||
Object object = getFieldByNumber(number);
|
||||
if (object == null)
|
||||
return null;
|
||||
|
||||
// when CIQ fields are used value arrays instead of single values are sometimes recorded
|
||||
if (!clazz.isArray() && object.getClass().isArray() && 0 < Array.getLength(object)) {
|
||||
object = Array.get(object, 0);
|
||||
}
|
||||
|
||||
return safeCast(object, clazz);
|
||||
}
|
||||
|
||||
public <T> T[] getArrayFieldByNumber(int number, final Class<T> clazz) {
|
||||
@@ -215,6 +224,18 @@ public class RecordData {
|
||||
return clazz.cast(object);
|
||||
}
|
||||
|
||||
if(object instanceof Number number){
|
||||
// some older Garmin devices encoded e.g.
|
||||
// [distance] and [enhanced_speed] as float instead of double
|
||||
// [cadence] as float instead of integer
|
||||
if(clazz.equals(Double.class)){
|
||||
return clazz.cast(number.doubleValue());
|
||||
}
|
||||
if(clazz.equals(Integer.class)){
|
||||
return clazz.cast(number.intValue());
|
||||
}
|
||||
}
|
||||
|
||||
LOG.error(
|
||||
"Unable to cast {} ({}) to {}, returning null - this is likely a bug. Record: {}",
|
||||
object,
|
||||
|
||||
Reference in New Issue
Block a user