You are here: Forum Home → ANT Developers Forums → ANT+ FIT Forum Has Moved → Thread
FileEncoder encode;
try {
encode = new FileEncoder(new java.io.File(file.getAbsolutePath()+".fit"), Fit.ProtocolVersion.V2_0);
} catch (FitRuntimeException e) {
System.err.println("Error opening file " + file.getName()+".fit");
return;
}
//Generate FileIdMessage
FileIdMesg fileIdMesg = new FileIdMesg(); // Every FIT file MUST contain a 'File ID' message as the first message
fileIdMesg.setManufacturer(15);
fileIdMesg.setType(com.garmin.fit.File.ACTIVITY);
fileIdMesg.setProduct(4);
fileIdMesg.setSerialNumber(1701L);
fileIdMesg.setTimeCreated(new DateTime(systemStartTime.getTime()));
fileIdMesg.setNumber(0);
encode.write(fileIdMesg); // Encode the FileIDMesg
byte[] appId = new byte[] {
0x1, 0x1, 0x2, 0x3,
0x5, 0x8, 0xD, 0x15,
0x22, 0x37, 0x59, (byte)0x90,
(byte)0xE9, 0x79, 0x62, (byte)0xDB
};
DeveloperDataIdMesg developerIdMesg = new DeveloperDataIdMesg();
for(int i = 0; i < appId.length; i++)
{
developerIdMesg.setApplicationId(i, appId[i]);
}
developerIdMesg.setDeveloperDataIndex((short)0);
encode.write(developerIdMesg);
FieldDescriptionMesg fieldDescMesg = new FieldDescriptionMesg();
fieldDescMesg.setDeveloperDataIndex((short)0);
fieldDescMesg.setFieldDefinitionNumber((short)0);
fieldDescMesg.setFitBaseTypeId((short)Fit.MAX_FIELD_SIZE);
fieldDescMesg.setFieldName(0, "Myinstrument");
fieldDescMesg.setUnits(0, "Myinstrument");
encode.write(fieldDescMesg);
RecordMesg record = new RecordMesg();
DeveloperField doughnutsEarnedField = new DeveloperField(fieldDescMesg, developerIdMesg);
record.addDeveloperField(doughnutsEarnedField);
// This is my code added to try to record something.
Date d=new Date();
DateTime d2 =new DateTime(d.getTime());
for (int ii=0;ii<ndatitot-2;ii++){
record.timestampToDateTime((d.getTime()));
record.setTimestamp(d2);
record.setPositionLat(495280430+ii);
record.setPositionLong(-872696681+ii);
record.setHeartRate((short)140);
record.setCadence((short)88);
record.setDistance(2080f);
record.setSpeed(2800f);
doughnutsEarnedField.setValue(ii+1);
encode.write(record);
fieldDescMesg.setFitBaseTypeId((short)Fit.MAX_FIELD_SIZE));
public class FitBaseType {
public static final short ENUM = 0;
public static final short SINT8 = 1;
public static final short UINT8 = 2;
public static final short SINT16 = 131;
public static final short UINT16 = 132;
public static final short SINT32 = 133;
public static final short UINT32 = 134;
public static final short STRING = 7;
public static final short FLOAT32 = 136;
public static final short FLOAT64 = 137;
public static final short UINT8Z = 10;
public static final short UINT16Z = 139;
public static final short UINT32Z = 140;
public static final short BYTE = 13;
public static final short INVALID = Fit.UINT8_INVALID;
}