forked from upstream-mirrors/OpenTracks
Fixing TCX generation:
- Cadence before Extensions - Adding BuildMajor and BuildMinor to Version since it seems to be required by http://connect.garmin.com - Version Values now only contain integers by splitting mytracks version code at dots, allows correct XML validation.
This commit is contained in:
@@ -174,6 +174,14 @@ public class TcxTrackWriter implements TrackFormatWriter {
|
|||||||
pw.print("</Value>");
|
pw.print("</Value>");
|
||||||
pw.println("</HeartRateBpm>");
|
pw.println("</HeartRateBpm>");
|
||||||
}
|
}
|
||||||
|
// TCX Trackpoint_t contains a sequence, <Cadence> needs to be put before <Extensions>
|
||||||
|
if (sensorData.hasCadence()
|
||||||
|
&& sensorData.getCadence().getState() == Sensor.SensorState.SENDING
|
||||||
|
&& sensorData.getCadence().hasValue()) {
|
||||||
|
pw.print(" <Cadence>");
|
||||||
|
pw.print(Math.min(254, sensorData.getCadence().getValue()));
|
||||||
|
pw.println("</Cadence>");
|
||||||
|
}
|
||||||
if (sensorData.hasPower()
|
if (sensorData.hasPower()
|
||||||
&& sensorData.getPower().getState() == Sensor.SensorState.SENDING
|
&& sensorData.getPower().getState() == Sensor.SensorState.SENDING
|
||||||
&& sensorData.getPower().hasValue()) {
|
&& sensorData.getPower().hasValue()) {
|
||||||
@@ -184,13 +192,6 @@ public class TcxTrackWriter implements TrackFormatWriter {
|
|||||||
pw.print("</Watts>");
|
pw.print("</Watts>");
|
||||||
pw.println("</TPX></Extensions>");
|
pw.println("</TPX></Extensions>");
|
||||||
}
|
}
|
||||||
if (sensorData.hasCadence()
|
|
||||||
&& sensorData.getCadence().getState() == Sensor.SensorState.SENDING
|
|
||||||
&& sensorData.getCadence().hasValue()) {
|
|
||||||
pw.print(" <Cadence>");
|
|
||||||
pw.print(Math.min(254, sensorData.getCadence().getValue()));
|
|
||||||
pw.println("</Cadence>");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pw.println(" </Trackpoint>");
|
pw.println(" </Trackpoint>");
|
||||||
@@ -217,10 +218,8 @@ public class TcxTrackWriter implements TrackFormatWriter {
|
|||||||
pw.println("<UnitId>0</UnitId>");
|
pw.println("<UnitId>0</UnitId>");
|
||||||
pw.println("<ProductID>0</ProductID>");
|
pw.println("<ProductID>0</ProductID>");
|
||||||
|
|
||||||
pw.println("<Version>");
|
writeVersion();
|
||||||
pw.println("<VersionMajor>0</VersionMajor>");
|
|
||||||
pw.println("<VersionMinor>0</VersionMinor>");
|
|
||||||
pw.println("</Version>");
|
|
||||||
pw.println("</Creator>");
|
pw.println("</Creator>");
|
||||||
pw.println(" </Activity>");
|
pw.println(" </Activity>");
|
||||||
pw.println(" </Activities>");
|
pw.println(" </Activities>");
|
||||||
@@ -241,15 +240,7 @@ public class TcxTrackWriter implements TrackFormatWriter {
|
|||||||
|
|
||||||
pw.println("<Build>");
|
pw.println("<Build>");
|
||||||
|
|
||||||
// The TCX spec for the Version tag is too strict to allow us to use our
|
writeVersion();
|
||||||
// user-visible version number, so we use our version code instead. We
|
|
||||||
// also set the minor version to 1 if this is a development build to
|
|
||||||
// signify that this build is newer than the one associated with the
|
|
||||||
// version code given in VersionMajor.
|
|
||||||
pw.println("<Version>");
|
|
||||||
pw.format("<VersionMajor>%s</VersionMajor>\n", SystemUtils.getMyTracksVersion(context));
|
|
||||||
pw.format("<VersionMinor>%d</VersionMinor>\n", SystemUtils.isRelease(context) ? 0 : 1);
|
|
||||||
pw.println("</Version>");
|
|
||||||
|
|
||||||
pw.format("<Type>%s</Type>\n", SystemUtils.isRelease(context) ? TCX_TYPE_RELEASE
|
pw.format("<Type>%s</Type>\n", SystemUtils.isRelease(context) ? TCX_TYPE_RELEASE
|
||||||
: TCX_TYPE_INTERNAL);
|
: TCX_TYPE_INTERNAL);
|
||||||
@@ -265,6 +256,30 @@ public class TcxTrackWriter implements TrackFormatWriter {
|
|||||||
// TODO Write out the waypoints somewhere.
|
// TODO Write out the waypoints somewhere.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void writeVersion() {
|
||||||
|
if (pw == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Splitting the myTracks version code into VersionMajor, VersionMinor and BuildMajor
|
||||||
|
// to fit the integer type requirement for these fields in the TCX spec.
|
||||||
|
// Putting a string like "x.x.x" into VersionMajor breaks XML validation.
|
||||||
|
// We also set the BuildMinor version to 1 if this is a development build to
|
||||||
|
// signify that this build is newer than the one associated with the
|
||||||
|
// version code given in BuildMajor.
|
||||||
|
|
||||||
|
String[] myTracksVersionComponents = SystemUtils.getMyTracksVersion(context).split("\\.");
|
||||||
|
|
||||||
|
pw.println("<Version>");
|
||||||
|
pw.format("<VersionMajor>%d</VersionMajor>\n", Integer.valueOf(myTracksVersionComponents[0]));
|
||||||
|
pw.format("<VersionMinor>%d</VersionMinor>\n", Integer.valueOf(myTracksVersionComponents[1]));
|
||||||
|
// TCX schema says these are optional but http://connect.garmin.com only accepts
|
||||||
|
// the TCX file when they are present.
|
||||||
|
pw.format("<BuildMajor>%d</BuildMajor>\n", Integer.valueOf(myTracksVersionComponents[2]));
|
||||||
|
pw.format("<BuildMinor>%d</BuildMinor>\n", SystemUtils.isRelease(context) ? 0 : 1);
|
||||||
|
pw.println("</Version>");
|
||||||
|
}
|
||||||
|
|
||||||
private String categoryToTcxSport(String category) {
|
private String categoryToTcxSport(String category) {
|
||||||
category = category.trim();
|
category = category.trim();
|
||||||
if (category.equalsIgnoreCase(TCX_SPORT_RUNNING)) {
|
if (category.equalsIgnoreCase(TCX_SPORT_RUNNING)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user