Skip to content
Browse files

Need to convert everything to use heap

  • Loading branch information...
1 parent f6d7326 commit 138c957db7ca5751f1bc803cd20f4bac46ea2bac @scheibo committed
Showing with 31 additions and 21 deletions.
  1. +4 −3 Makefile
  2. +2 −1 activity.h
  3. +20 −9 fix.c
  4. +2 −1 fix.h
  5. +3 −7 gpx.c
View
7 Makefile
@@ -5,6 +5,7 @@ CFLAGS += $(WARN) $(DEBUG) -pthread
#TARGET = fitparse
#OBJECTS = activity.o fit.o tcx.o gpx.o
+HEADERS = $(wildcard *.h)
default: gpx
@@ -13,13 +14,13 @@ all: gpx
gpx: gpx.o activity.o util.o lib/mxml/libmxml.a lib/date/libdate.a
$(CC) $^ $(CFLAGS) -o $@
-gpx.o: gpx.c gpx.h lib/mxml/mxml.h
+gpx.o: gpx.c gpx.h lib/mxml/mxml.h $(HEADERS)
$(CC) $(CFLAGS) -Ilib/mxml -c $< -o $@
-util.o: util.c lib/date/date.h
+util.o: util.c lib/date/date.h $(HEADERS)
$(CC) $(CFLAGS) -Ilib/date -c $< -o $@
-activity.o: activity.c
+activity.o: activity.c $(HEADERS)
$(CC) $(CFLAGS) -c $< -o $@
lib/mxml/Makefile:
View
3 activity.h
@@ -112,6 +112,7 @@ typedef struct {
uint32_t *laps; /* TODO array of timestamps, always at least one */
DataPoint *data_points;
DataPoint *last_point;
+ DataPoint has_data;
/*
//Summary summary; // can include derived statistics (totalAscent, NP, avg)
//Summary * lap_summaries; // can include derived statistics (totalAscent, NP,
@@ -120,7 +121,7 @@ typedef struct {
} Activity;
#define activity_new() \
- { UnknownSport, NULL, NULL }
+ { UnknownSport, NULL, NULL, NULL, {0} }
void activity_destroy(Activity *a);
int activity_add_point(Activity *a, DataPoint *point);
View
29 fix.c
@@ -4,32 +4,43 @@
#include "activity.h"
#include "fix.h"
-/* used to handle gaps in recording by inserting interpolated/zero samples to ensure dataPoints are contiguous in time */
+/* used to handle gaps in recording by inserting interpolated/zero samples to
+ * ensure dataPoints are contiguous in time */
int fix_gps(Activity *a) {
DataPoint *fill_data, *last_good = NULL;
int errors = 0, last_good_index = -1, index = 0, fill_index;
double delta_latitude, delta_longitude;
// ignore null or files without GPS data
- if (!a || !a->data_points || !a->has_data->latitude || !a->has_data->longitude) { /* TODO add has_data */
+ if (!a || !a->data_points || !a->has_data.latitude ||
+ !a->has_data.longitude) { /* TODO add has_data */
return -1;
}
for (data = a->data_points; data; data = data->next, index++) {
/* is this one decent? */
- if (data->latitude >= -90 && data->latitude <= 90 && data->longitude >= -180 && data->longitude <= 180) {
+ if (data->latitude >= -90 && data->latitude <= 90 &&
+ data->longitude >= -180 && data->longitude <= 180) {
if (last_good && (last_good->next != data)) {
/* interpolate from last_good to here then set last_good to here */
- delta_latitude = (data->latitude - last_good->latitude) / (double)(index-last_good_index);
- delta_longitude = (data->longitude - last_good->longitude) / (double)(index-last_good_index);
- for (fill_data = last_good->next, fill_index = last_good_index + 1; fill_data != data; fill_data = fill_data->next, fill_index++) {
- fill_data->latitude = last_good->latitude + (double)((fill_index-last_good_index)*delta_latitude);
- fill_data->longitude = last_good->longitude + (double)((fill_index-last_good_index)*delta_longitude);
+ delta_latitude = (data->latitude - last_good->latitude) /
+ (double)(index - last_good_index);
+ delta_longitude = (data->longitude - last_good->longitude) /
+ (double)(index - last_good_index);
+ for (fill_data = last_good->next, fill_index = last_good_index + 1;
+ fill_data != data; fill_data = fill_data->next, fill_index++) {
+ fill_data->latitude =
+ last_good->latitude +
+ (double)((fill_index - last_good_index) * delta_latitude);
+ fill_data->longitude =
+ last_good->longitude +
+ (double)((fill_index - last_good_index) * delta_longitude);
errors++;
}
} else if (!last_good) {
/* fill to front */
- for (fill_data = a->data_points; fill_data != data; fill_data = fill_data->next) {
+ for (fill_data = a->data_points; fill_data != data;
+ fill_data = fill_data->next) {
fill_data->latitude = data->latitude;
fill_data->longitude = data->longitude;
errors++;
View
3 fix.h
@@ -7,7 +7,8 @@ int fix_gps(Activity *a);
/*
int fix_gaps(Activity *a);
int fix_spikes(Activity *a);
-int fix_hr(Activity *a); // TODO probably needs HR max from athletes and other values?
+int fix_hr(Activity *a); // TODO probably needs HR max from athletes and other
+values?
*/
#endif /* _FIX_H_ */
View
10 gpx.c
@@ -65,20 +65,16 @@ static int sax_cb(mxml_node_t *node, mxml_sax_event_t event, void *sax_data) {
return 0;
} else if (!strcmp(name, "time")) {
state->data.timestamp = parse_timestamp(data);
- if (!state->data.timestamp) state->data.timestamp = UNSET_TIMESTAMP;
} else if (!strcmp(name, "ele")) {
state->data.altitude = (int32_t)(strtod(data, &end) * 1000);
if (*end) state->data.altitude = UNSET_ALTITUDE;
- } else if (!strcmp(name, "gpxtpx:hr")) {
+ } else if (!strcmp(name, "gpxdata:hr") || !strcmp(name, "gpxtpx:hr")) {
state->data.heart_rate = (uint8_t) strtod(data, &end);
if (*end) state->data.heart_rate = UNSET_HEART_RATE;
- } else if (!strcmp(name, "gpxdata:hr")) {
- state->data.heart_rate = (uint8_t) strtod(data, &end);
- if (*end) state->data.heart_rate = UNSET_HEART_RATE;
- } else if (!strcmp(name, "gpxdata:temp")) {
+ } else if (!strcmp(name, "gpxdata:temp") || !strcmp(name, "gpxtpx:atemp")) {
state->data.temperature = (int8_t) strtod(data, &end);
if (*end) state->data.temperature = UNSET_TEMPERATURE;
- } else if (!strcmp(name, "gpxdata:cadence")) {
+ } else if (!strcmp(name, "gpxdata:cadence") || !strcmp(name, "gpxtpx:cad")) {
state->data.cadence = (uint8_t) strtod(data, &end);
if (*end) state->data.cadence = UNSET_CADENCE;
} else if (!strcmp(name, "gpxdata:bikepower")) {

0 comments on commit 138c957

Please sign in to comment.
Something went wrong with that request. Please try again.