IndexOutOfBoundsException添加Garmin FIT RecordMesg自定义字段

时间:2017-02-27 17:35:06

标签: garmin

我的应用会生成.Fit文件。

它适用于标准API。但是当我尝试添加自定义字段时,它会被忽略或无法被客户端解析。

我正在使用FIT SDK 2.0。

fit::DeveloperDataIdMesg DPSdevIdMesg;
    uint8_t appId[] = {
      0x67, 0x72, 0x69, 0x73, 0x68, 0x61, 0x20, 0x68, 0x61, 0x20, 0x6d, 0x65, 0x6c, 0x65, 0x6b, 0x68
    };
    for (int appIdx = 0; appIdx < 16; ++appIdx) {
        DPSdevIdMesg.SetApplicationId( appIdx, appId[appIdx] );
    }

    DPSdevIdMesg.SetDeveloperDataIndex(0);
    encode.Write(DPSdevIdMesg);

fit::FieldDescriptionMesg DPSfieldDescMesg;
    DPSfieldDescMesg.SetDeveloperDataIndex(0);
    DPSfieldDescMesg.SetFieldDefinitionNumber(0);
    DPSfieldDescMesg.SetFitBaseTypeId(FIT_FIT_BASE_TYPE_FLOAT64);
    FIT_WSTRING DPSname = L"DPS";
    DPSfieldDescMesg.SetFieldName(0,DPSname );
    DPSfieldDescMesg.SetUnits( 0, L"m" );
    encode.Write(DPSfieldDescMesg);

for (size_t k = 0; k < intervals_size; k++) {
  std::vector<commons::timestamped<commons::gps_point>> gps_points =  interval_report.gps_points;
            size_t gpsPointsSize = gps_points.size();

            for (size_t j = 0; j < gpsPointsSize; j++)
            {
                commons::timestamped<commons::gps_point> obj = gps_points[j];
                commons::gps_point point = obj.value;
               .
               .

                fit::RecordMesg record;
                fit::DeveloperField df(DPSfieldDescMesg, DPSdevIdMesg);
                double dps = point.dps;
                record.AddDeveloperField(df);
                df.SetFLOAT64Value(0.0);

                .
                .
                record.SetPositionLong(pow(2, 31) * (longitudeX) / 180.0);
                record.SetPositionLat(pow(2, 31) * (latitudeY) / 180.0);
                record.SetGpsAccuracy(accuracy);
                encode.Write(record);
    }
}

当我尝试将其解析为CSV文件时抛出异常。

FIT CSV Tool - Protocol 2.0 Profile 20.22 Release
Exception in thread "main" java.lang.RuntimeException:  java.lang.IndexOutOfBoundsException: Index: 1, Size: 1
    at com.garmin.fit.csv.CSVTool.run(CSVTool.java:232)
    at com.garmin.fit.csv.CSVTool.main(CSVTool.java:302)
Caused by: java.lang.IndexOutOfBoundsException: Index: 1, Size: 1
    at java.util.ArrayList.rangeCheck(Unknown Source)
    at java.util.ArrayList.get(Unknown Source)
    at com.garmin.fit.Decode.read(Decode.java:975)
    at com.garmin.fit.Decode.resume(Decode.java:365)
    at com.garmin.fit.Decode.read(Decode.java:344)
    at com.garmin.fit.csv.CSVTool.run(CSVTool.java:206)

0 个答案:

没有答案
相关问题