mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Dive site: create new dive site at location from GPS data
Some dive computers save GPS data. Currently, this is stored by libdivecomputer in an "extra field". When generating a new dive site for a dive try to use this data to place the dive site. To do so, create a "dive_get_gps_location()" function. This function can be extended later to use e.g. event. When creating a dive site, use the result of this function over a potential pre-existing dive site. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
c529cfd361
commit
bab7033ccb
3 changed files with 56 additions and 0 deletions
47
core/dive.c
47
core/dive.c
|
@ -4500,6 +4500,53 @@ int dive_has_gps_location(const struct dive *dive)
|
|||
return dive_site_has_gps_location(dive->dive_site);
|
||||
}
|
||||
|
||||
/* Extract GPS location of a dive computer stored in the GPS1
|
||||
* or GPS2 extra data fields */
|
||||
static location_t dc_get_gps_location(const struct divecomputer *dc)
|
||||
{
|
||||
location_t res = { };
|
||||
|
||||
for (struct extra_data *data = dc->extra_data; data; data = data->next) {
|
||||
if (!strcmp(data->key, "GPS1")) {
|
||||
parse_location(data->value, &res);
|
||||
/* If we found a valid GPS1 field exit early since
|
||||
* it has priority over GPS2 */
|
||||
if (has_location(&res))
|
||||
break;
|
||||
} else if (!strcmp(data->key, "GPS2")) {
|
||||
/* For GPS2 fields continue searching, as we might
|
||||
* still find a GPS1 field */
|
||||
parse_location(data->value, &res);
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
/* Get GPS location for a dive. Highest priority is given to the GPS1
|
||||
* extra data written by libdivecomputer, as this comes from a real GPS
|
||||
* device. If that doesn't exits, use the currently set dive site.
|
||||
* This function is potentially slow, therefore only call sparingly
|
||||
* and remember the result.
|
||||
*/
|
||||
location_t dive_get_gps_location(const struct dive *d)
|
||||
{
|
||||
location_t res = { };
|
||||
|
||||
for (const struct divecomputer *dc = &d->dc; dc; dc = dc->next) {
|
||||
res = dc_get_gps_location(dc);
|
||||
if (has_location(&res))
|
||||
return res;
|
||||
}
|
||||
|
||||
/* No libdivecomputer generated GPS data found.
|
||||
* Let's use the location of the current dive site.
|
||||
*/
|
||||
if (d->dive_site)
|
||||
res = d->dive_site->location;
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
/* When evaluated at the time of a gasswitch, this returns the new gas */
|
||||
struct gasmix get_gasmix(const struct dive *dive, const struct divecomputer *dc, int time, const struct event **evp, struct gasmix gasmix)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue