In FIT SDK 1.0 I see there are example encode and decode applications for C and C++ but not for Java, so I am starting from scratch trying to read and parse a FIT file.
Does anyone know of any examples posted by Dynastream or customers for reading and decoding FIT files using the Java SDK?
I whipped up something really quick and I am already running into a blocker. When I try to decode a FIT file I get a "FitRuntimeExeption: FIT decode error: File is not FIT format. Check file header data type." error. The Decode.isFit method returns true but the Decode.checkIntegrity method returns false for all of the FIT files I have tried.
All of the FIT files I have tried upload successfully to Garmin Connect and successfully convert to CSV using the FIT to CSV tool, and I even tried the Activity.fit file included with the SDK download unsuccessfully, so I am pretty sure I am doing something wrong as opposed to there being an issue with the files themselves.
I've attached a ZIP file with my Java file and 4 different FIT Activity files. I've also copied and pasted the contents of the Java file below.
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import com.garmin.fit.Decode;
import com.garmin.fit.FitRuntimeException;
public class Test {
//private static String filePath = "20100501-094759-1-1018-ANTFS-4.FIT";
//private static String filePath = "2010-08-12-17-44-48.fit";
//private static String filePath = "FR310/20110109-110521-1-1018-ANTFS-4.FIT";
private static String filePath = "Activity.fit";
private static File fitFile;
private static FileInputStream fitFileInputStream;
private static Decode fitFileDecode;
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
File fitFile = new File(filePath);
try {
fitFileInputStream = new FileInputStream(fitFile);
if (!fitFile.canRead()) throw new Exception("Unable to read the input file: " + filePath);
if (!Decode.isFit(fitFileInputStream)) throw new Exception("The following file is not a FIT file: " + filePath);
/*if (!Decode.checkIntegrity(fitFileInputStream)) throw new Exception("There are integrity issues with the following FIT file: " + filePath);*/
fitFileDecode = new Decode();
System.out.println(fitFileDecode.read(fitFileInputStream));
} catch (FileNotFoundException fnfe) {
System.out.println("FileNotFoundException: " + fnfe.getMessage());
} catch (FitRuntimeException fre) {
System.out.println("FitRuntimeExeption: " + fre.getMessage());
} catch (Exception e) {
System.out.println("Exeption: " + e.getMessage());
}
}
} [file name=Test.zip size=96069]
http://www.thisisant.com/images/fbfiles/files/Test.zip[/file]