Skip to content

Commit

Permalink
FitFile : Add IpBike and correct float32 for endian
Browse files Browse the repository at this point in the history
Fix #3682
  • Loading branch information
grauser committed Jul 11, 2021
1 parent c78fcda commit 566d562
Showing 1 changed file with 24 additions and 3 deletions.
27 changes: 24 additions & 3 deletions src/FileIO/FitRideFile.cpp
Expand Up @@ -300,13 +300,26 @@ struct FitFileReaderState
return i == 0x00000000 ? NA_VALUE : i;
}

fit_float_value read_float32(int *count = NULL) {
fit_float_value read_float32(bool is_big_endian, int *count = NULL) {
float f;
if (file.read(reinterpret_cast<char*>(&f), 4) != 4)
throw TruncatedRead();
if (count)
(*count) += 4;

if (is_big_endian) {
float f2;
char *floatToConvert = ( char* ) & f;
char *returnFloat = ( char* ) & f2;

// swap the bytes into a temporary buffer
returnFloat[0] = floatToConvert[3];
returnFloat[1] = floatToConvert[2];
returnFloat[2] = floatToConvert[1];
returnFloat[3] = floatToConvert[0];
f = f2;
}

return f;
}

Expand Down Expand Up @@ -486,7 +499,15 @@ struct FitFileReaderState
case 2: return "Pioneer SGX-CA500";
default: return QString("Pioneer %1").arg(prod);
}
} else if (manu == 69) {
} else if (manu == 54) {
// ifor_powell
switch (prod) {
case -1: return "Ifor powell";
case 1: return "IpBike";
default: return QString("Ifor powell %1").arg(prod);
}
}
else if (manu == 69) {
// Stages Cycling
switch (prod) {
case -1: return "Stages Cycling";
Expand Down Expand Up @@ -2940,7 +2961,7 @@ struct FitFileReaderState
size = 4;
if (field.size==size) {
value.type = FloatValue;
value.f = read_float32(&count);
value.f = read_float32(def.is_big_endian, &count);
if (value.f != value.f) // No NAN
value.f = 0;
} else { // Multi-values
Expand Down

0 comments on commit 566d562

Please sign in to comment.