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 <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Linus Torvalds 2018-08-29 18:51:51 -07:00 committed by Dirk Hohndel
parent 156e053050
commit f59679320a

View file

@ -581,6 +581,8 @@ static void set_dc_serial(struct divecomputer *dc, const char *serial)
dc->deviceid = calculate_string_hash(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) 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 // 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); dive->dc.fw_version = strdup(str->value);
return; 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 #endif