Welcome Guest,Register Now
Log In

ANT Forum

Welcome guest, please Login or Register

   

Example encode and decode applications for Java SDK

Rank

Total Posts: 10

Joined 2010-11-24

PM

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]      
RankRankRankRank

Total Posts: 116

Joined 2008-11-21

PM

It does seem that all the files are formatted correctly and that there is an error in your code. Unfortunately we currently do not have enough resources to provide java encode/decode reference code or support.

At this time, the best we can suggeest is to use the FitCVSTool source code as reference.      
RankRankRankRank

Total Posts: 523

Joined 2012-11-15

PM

Since I want to do everything in Java, and use the native Java messages, it doesn't make sense for me to export as CSV.

All I need is one example of reading in a FIT file using the Java SDK and iterating through the messages. There is a few examples for the C SDK, but nothing for Java.

You are not able to provide a simple example? Forget about looking at my code or helping with that, but just one basic working sample using the Java SDK to read in a FIT file and iterate through the messages? This is something that should have been provided in the first place.      
Rank

Total Posts: 1

Joined 2009-07-08

PM

Hi,

So did you manage to deal with your problem with full java code ? I'm also trying to code a full native java application to get data from sensor with USB stick 2. And as I want it to be plateform independant, your help and experience would be very pleased. Thanks a lot.

Hugo      
RankRankRankRank

Total Posts: 116

Joined 2008-11-21

PM

this is scheduled for an upcoming release... no official date for that yet.

If time is short, you can look at the FIT CSV Tool source code and create something from that.      
Rank

Total Posts: 10

Joined 2010-11-24

PM

One of our software partners figured it out, but I do not have the code.      
Rank

Total Posts: 9

Joined 0

PM

can somebody take a look here http://www.thisisant.com/forum/viewthread/4319/ i really need help to figure out this.. ;( Thanks in advance..      
Rank

Total Posts: 1

Joined 2017-08-29

PM

After almost 7 years I doubt you care any more wink but in case anyone else arrives here (as I did) ...

I suspect the problem was that you were reusing the input stream - so the isFit works because it gets the new input stream but by the time you call the checkIntegrity method the stream has already been fully consumed so the method call returns false because it gets no data at all. Same issue with the read method call - it also reuses the input stream.

HTH (someone)
Ivor