From f59679320a5cf42280e2877b7a314fd75116d08a Mon Sep 17 00:00:00 2001 From: Linus Torvalds Date: Wed, 29 Aug 2018 18:51:51 -0700 Subject: parse "GPS" string fields and turn them into dive sites when downloading Dive computers that do GPS can report their GPS data as one or more string fields, and if the first tree letters of the description is "GPS", then we'll take the string and turn it into a dive site for that dive. Signed-off-by: Linus Torvalds Signed-off-by: Dirk Hohndel --- core/libdivecomputer.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'core/libdivecomputer.c') diff --git a/core/libdivecomputer.c b/core/libdivecomputer.c index 51fc6f8b8..44bf78b80 100644 --- a/core/libdivecomputer.c +++ b/core/libdivecomputer.c @@ -581,6 +581,8 @@ static void set_dc_serial(struct divecomputer *dc, const char *serial) dc->deviceid = calculate_string_hash(serial); } +extern degrees_t parse_degrees(char *buf, char **end); + static void parse_string_field(struct dive *dive, dc_field_string_t *str) { // Our dive ID is the string hash of the "Dive ID" string @@ -598,6 +600,18 @@ static void parse_string_field(struct dive *dive, dc_field_string_t *str) dive->dc.fw_version = strdup(str->value); return; } + /* GPS data? */ + if (!strncmp(str->desc, "GPS", 3)) { + char *line = (char *) str->value; + degrees_t latitude, longitude; + + latitude = parse_degrees(line, &line); + if (*line == ',') line++; + longitude = parse_degrees(line, &line); + + if (latitude.udeg && longitude.udeg) + dive->dive_site_uuid = create_dive_site_with_gps(str->value, latitude, longitude, dive->when); + } } #endif -- cgit v1.2.3-70-g09d2