0

I'm developing an application in Java that reads and displays geographic data produced by an instrument (it has a GPS integrated). I would develop the export function in ".fit" format of such data to use them in lots free applications. I read this "ANT +" documentation and the sdk stuff, but i have a problem developing the following code. The file is correctly generated in ".fit" format, but this file is not compatible (no web or desktop application can read this data). it seems as if something was missing. into the SDK although there are some examples in Java but they are not clear. Thank you The code is this:

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);

This code is necessary because every ".fit" file need this. as explained in doc.

Then i found the following code for java.

 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, "Bepop2");
  fieldDescMesg.setUnits(0, "Bepop22");
  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);
4

1 回答 1

3

在此处从 FIT 论坛重新发布我的答案(https://www.thisisant.com/forum/viewthread/6501/

如上所述对文件进行编码Fit.ProtocolVersion.V2_0是 FIT 协议的一项重大更改,旧的(即 FIT 协议版本 1.0)解码器将无法正确解码生成的文件。

FIT 2.0 在 5 月初才退出 beta 阶段,因此许多使用 FIT SDK 的应用程序可能还没有更新。

如果编码器是通过指定创建的,Fit.ProtocolVersion.V1_0则将创建一个 FIT 协议版本 1.0 兼容文件(假设不使用 2.0 功能)。

于 2016-06-02T04:13:30.923 回答