use of nodomain.freeyourgadget.gadgetbridge.model.ActivityPoint in project Gadgetbridge by Freeyourgadget.
the class GPXExporter method exportTrack.
private void exportTrack(XmlSerializer ser, ActivityTrack track) throws IOException, GPXTrackEmptyException {
String uuid = UUID.randomUUID().toString();
ser.startTag(NS_GPX_URI, "trk");
ser.startTag(NS_GPX_URI, "extensions");
ser.startTag(NS_GPX_URI, OPENTRACKS_PREFIX + ":trackid").text(uuid).endTag(NS_GPX_URI, OPENTRACKS_PREFIX + ":trackid");
ser.endTag(NS_GPX_URI, "extensions");
ser.startTag(NS_GPX_URI, "trkseg");
List<ActivityPoint> trackPoints = track.getTrackPoints();
String source = getSource(track);
boolean atLeastOnePointExported = false;
for (ActivityPoint point : trackPoints) {
atLeastOnePointExported |= exportTrackPoint(ser, point, source, trackPoints);
}
if (!atLeastOnePointExported) {
throw new GPXTrackEmptyException();
}
ser.endTag(NS_GPX_URI, "trkseg");
ser.endTag(NS_GPX_URI, "trk");
}
use of nodomain.freeyourgadget.gadgetbridge.model.ActivityPoint in project Gadgetbridge by Freeyourgadget.
the class GPXExporter method findClosestSensibleActivityPoint.
@Nullable
private ActivityPoint findClosestSensibleActivityPoint(Date time, List<ActivityPoint> trackPoints) {
ActivityPoint closestPointItem = null;
HeartRateUtils heartRateUtilsInstance = HeartRateUtils.getInstance();
// minimum distance is 2min
long lowestDifference = 60 * 2 * 1000;
for (ActivityPoint pointItem : trackPoints) {
int hrItem = pointItem.getHeartRate();
if (heartRateUtilsInstance.isValidHeartRateValue(hrItem)) {
Date timeItem = pointItem.getTime();
if (timeItem.after(time) || timeItem.equals(time)) {
// we assume that the given trackPoints are sorted in time ascending order (oldest first)
break;
}
long difference = time.getTime() - timeItem.getTime();
if (difference < lowestDifference) {
lowestDifference = difference;
closestPointItem = pointItem;
}
}
}
return closestPointItem;
}
use of nodomain.freeyourgadget.gadgetbridge.model.ActivityPoint in project Gadgetbridge by Freeyourgadget.
the class HuamiActivityDetailsParser method consumeGPSAndUpdateBaseLocation.
private int consumeGPSAndUpdateBaseLocation(byte[] bytes, int offset, long timeOffset) {
int i = 0;
int longitudeDelta = BLETypeConversions.toInt16(bytes[offset + i++], bytes[offset + i++]);
int latitudeDelta = BLETypeConversions.toInt16(bytes[offset + i++], bytes[offset + i++]);
int altitudeDelta = BLETypeConversions.toInt16(bytes[offset + i++], bytes[offset + i++]);
baseLongitude += longitudeDelta;
baseLatitude += latitudeDelta;
if (baseAltitude != -20000) {
baseAltitude += altitudeDelta;
}
GPSCoordinate coordinate = new GPSCoordinate(convertHuamiValueToDecimalDegrees(baseLongitude), convertHuamiValueToDecimalDegrees(baseLatitude), baseAltitude);
ActivityPoint ap = getActivityPointFor(timeOffset, coordinate);
ap.setLocation(coordinate);
add(ap);
return i;
}
use of nodomain.freeyourgadget.gadgetbridge.model.ActivityPoint in project Gadgetbridge by Freeyourgadget.
the class HuamiActivityDetailsParserTest method testGPXExport.
@Test
public void testGPXExport() throws Exception {
BipActivitySummary summary = createSummary();
int baseLongi = BLETypeConversions.toUint32((byte) 0xd6, (byte) 0xc4, (byte) 0x62, (byte) 0x02);
int baseLati = BLETypeConversions.toUint32((byte) 0xff, (byte) 0xa9, (byte) 0x61, (byte) 0x9);
int baseAlti = BLETypeConversions.toUint32((byte) 0x30, (byte) 0x0, (byte) 0x0, (byte) 0x0);
summary.setBaseLongitude(baseLongi);
summary.setBaseLatitude(baseLati);
summary.setBaseAltitude(baseAlti);
HuamiActivityDetailsParser parser = new HuamiActivityDetailsParser(summary);
parser.setSkipCounterByte(true);
try (InputStream in = getContents(DETAILS_1)) {
ActivityTrack track = parser.parse(FileUtils.readAll(in, MAX_DETAILS));
List<ActivityPoint> trackPoints = track.getTrackPoints();
assertEquals(972, trackPoints.size());
GPXExporter exporter = new GPXExporter();
exporter.setIncludeHeartRate(false);
exporter.setCreator(getClass().getName());
File targetFile = File.createTempFile("gadgetbridge-track", ".gpx");
System.out.println("Writing GPX file: " + targetFile);
exporter.performExport(track, targetFile);
assertTrue(targetFile.length() > 1024);
}
}
use of nodomain.freeyourgadget.gadgetbridge.model.ActivityPoint in project Gadgetbridge by Freeyourgadget.
the class HuamiActivityDetailsParserTest method testActivityDetails.
@Test
public void testActivityDetails() throws Exception {
BipActivitySummary summary = createSummary();
HuamiActivityDetailsParser parser = new HuamiActivityDetailsParser(summary);
parser.setSkipCounterByte(true);
try (InputStream in = getContents(DETAILS_1)) {
ActivityTrack track = parser.parse(FileUtils.readAll(in, MAX_DETAILS));
assertEquals("SuperBand 2000", track.getDevice().getName());
assertEquals("Elvis", track.getUser().getName());
List<ActivityPoint> trackPoints = track.getTrackPoints();
assertEquals(972, trackPoints.size());
}
}
Aggregations