2017-04-27 18:18:03 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2017-03-11 20:08:31 +00:00
|
|
|
#ifdef __clang__
|
2016-03-09 18:18:48 +00:00
|
|
|
// Clang has a bug on zero-initialization of C structs.
|
|
|
|
#pragma clang diagnostic ignored "-Wmissing-field-initializers"
|
2017-03-11 20:08:31 +00:00
|
|
|
#endif
|
2016-03-09 18:18:48 +00:00
|
|
|
|
2018-05-22 07:07:42 +00:00
|
|
|
#include "ssrf.h"
|
2024-02-28 21:01:51 +00:00
|
|
|
|
2011-08-28 23:58:26 +00:00
|
|
|
#include <stdio.h>
|
2011-08-30 00:51:54 +00:00
|
|
|
#include <ctype.h>
|
|
|
|
#include <string.h>
|
2011-08-30 23:23:47 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <errno.h>
|
2011-11-05 20:51:37 +00:00
|
|
|
#include <unistd.h>
|
2013-01-31 00:08:36 +00:00
|
|
|
#include <assert.h>
|
2011-08-28 23:58:26 +00:00
|
|
|
#include <libxml/parser.h>
|
2013-03-15 17:02:14 +00:00
|
|
|
#include <libxml/parserInternals.h>
|
2011-08-28 23:58:26 +00:00
|
|
|
#include <libxml/tree.h>
|
2011-11-05 10:39:17 +00:00
|
|
|
#include <libxslt/transform.h>
|
2014-07-12 12:51:03 +00:00
|
|
|
#include <libdivecomputer/parser.h>
|
2013-10-06 15:55:58 +00:00
|
|
|
|
|
|
|
#include "gettext.h"
|
|
|
|
|
2020-10-25 12:28:55 +00:00
|
|
|
#include "dive.h"
|
core: introduce divelog structure
The parser API was very annoying, as a number of tables
to-be-filled were passed in as pointers. The goal of this
commit is to collect all these tables in a single struct.
This should make it (more or less) clear what is actually
written into the divelog files.
Moreover, it should now be rather easy to search for
instances, where the global logfile is accessed (and it
turns out that there are many!).
The divelog struct does not contain the tables as substructs,
but only collects pointers. The idea is that the "divelog.h"
file can be included without all the other files describing
the numerous tables.
To make it easier to use from C++ parts of the code, the
struct implements a constructor and a destructor. Sadly,
we can't use smart pointers, since the pointers are accessed
from C code. Therfore the constructor and destructor are
quite complex.
The whole commit is large, but was mostly an automatic
conversion.
One oddity of note: the divelog structure also contains
the "autogroup" flag, since that is saved in the divelog.
This actually fixes a bug: Before, when importing dives
from a different log, the autogroup flag was overwritten.
This was probably not intended and does not happen anymore.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2022-11-08 20:31:08 +00:00
|
|
|
#include "divelog.h"
|
2019-03-04 22:20:29 +00:00
|
|
|
#include "divesite.h"
|
2019-08-05 17:41:15 +00:00
|
|
|
#include "errorhelper.h"
|
2017-11-27 17:41:10 +00:00
|
|
|
#include "parse.h"
|
2022-08-30 16:13:13 +00:00
|
|
|
#include "subsurface-float.h"
|
|
|
|
#include "subsurface-string.h"
|
2020-05-01 12:07:59 +00:00
|
|
|
#include "subsurface-time.h"
|
2019-05-31 14:09:14 +00:00
|
|
|
#include "trip.h"
|
Assemble the actual Suunto serial number
It turns out that the serial number returned by libdivecomputer isn't
really the serial number as interpreted by the vendor. Those tend to be
strings, but libdivecomputer gives us a 32bit number.
Some experimenting showed that for the Suunto devies tested the serial
number is encoded in that 32bit number:
It so happens that the Suunto serial number strings are strings that have
all numbers, but they aren't *one* number. They are four bytes
representing two numbers each, and the "23500027" string is actually the
four bytes 23 50 00 27 (0x17 0x32 0x00 0x1b). And libdivecomputer has
incorrectly parsed those four bytes as one number, not as the encoded
serial number string it is. So the value 389152795 is actually hex
0x1732001b, which is 0x17 0x32 0x00 0x1b, which is - 23 50 00 27.
This should be done by libdivecomputer, but hey, in the meantime this at
least shows the concept. And helps test the XML save/restore code.
It depends on the two patches that create the whole "device.c"
infrastructure, of course. With this, my dive file ends up having the
settings section look like this:
<divecomputerid model='Suunto Vyper Air' deviceid='d4629110'
serial='01201094' firmware='1.1.22'/>
<divecomputerid model='Suunto HelO2' deviceid='995dd566'
serial='23500027' firmware='1.0.4'/>
where the format of the firmware version is something I guessed at,
but it was the obvious choice (again, it's byte-based, I'm ignoring
the high byte that is zero for both of my Suuntos).
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-10 00:14:21 +00:00
|
|
|
#include "device.h"
|
2014-05-28 06:55:46 +00:00
|
|
|
#include "membuffer.h"
|
2020-04-10 07:42:14 +00:00
|
|
|
#include "picture.h"
|
2018-03-01 21:12:56 +00:00
|
|
|
#include "qthelper.h"
|
2020-10-25 12:28:55 +00:00
|
|
|
#include "sample.h"
|
2019-05-30 16:29:36 +00:00
|
|
|
#include "tag.h"
|
2020-10-17 18:15:23 +00:00
|
|
|
#include "xmlparams.h"
|
2011-08-30 23:42:05 +00:00
|
|
|
|
2015-02-13 07:35:52 +00:00
|
|
|
int last_xml_version = -1;
|
2011-08-30 20:48:05 +00:00
|
|
|
|
2020-10-17 18:15:23 +00:00
|
|
|
static xmlDoc *test_xslt_transforms(xmlDoc *doc, const struct xml_params *params);
|
2013-02-22 19:20:46 +00:00
|
|
|
|
2018-10-17 16:45:22 +00:00
|
|
|
static void divedate(const char *buffer, timestamp_t *when, struct parser_state *state)
|
2011-08-30 22:22:48 +00:00
|
|
|
{
|
2014-02-16 23:42:56 +00:00
|
|
|
int d, m, y;
|
|
|
|
int hh, mm, ss;
|
2013-01-29 05:07:52 +00:00
|
|
|
|
2014-02-16 23:42:56 +00:00
|
|
|
hh = 0;
|
|
|
|
mm = 0;
|
|
|
|
ss = 0;
|
2013-01-29 05:07:52 +00:00
|
|
|
if (sscanf(buffer, "%d.%d.%d %d:%d:%d", &d, &m, &y, &hh, &mm, &ss) >= 3) {
|
|
|
|
/* This is ok, and we got at least the date */
|
|
|
|
} else if (sscanf(buffer, "%d-%d-%d %d:%d:%d", &y, &m, &d, &hh, &mm, &ss) >= 3) {
|
|
|
|
/* This is also ok */
|
2011-09-02 00:13:39 +00:00
|
|
|
} else {
|
|
|
|
fprintf(stderr, "Unable to parse date '%s'\n", buffer);
|
2013-01-29 05:07:52 +00:00
|
|
|
return;
|
2011-08-30 22:22:48 +00:00
|
|
|
}
|
2018-10-17 16:45:22 +00:00
|
|
|
state->cur_tm.tm_year = y;
|
|
|
|
state->cur_tm.tm_mon = m - 1;
|
|
|
|
state->cur_tm.tm_mday = d;
|
|
|
|
state->cur_tm.tm_hour = hh;
|
|
|
|
state->cur_tm.tm_min = mm;
|
|
|
|
state->cur_tm.tm_sec = ss;
|
2013-01-29 05:07:52 +00:00
|
|
|
|
2018-10-17 16:45:22 +00:00
|
|
|
*when = utc_mktime(&state->cur_tm);
|
2011-08-30 22:22:48 +00:00
|
|
|
}
|
|
|
|
|
2018-10-17 16:45:22 +00:00
|
|
|
static void divetime(const char *buffer, timestamp_t *when, struct parser_state *state)
|
2011-08-30 22:22:48 +00:00
|
|
|
{
|
2014-02-16 23:42:56 +00:00
|
|
|
int h, m, s = 0;
|
2011-08-30 22:22:48 +00:00
|
|
|
|
|
|
|
if (sscanf(buffer, "%d:%d:%d", &h, &m, &s) >= 2) {
|
2018-10-17 16:45:22 +00:00
|
|
|
state->cur_tm.tm_hour = h;
|
|
|
|
state->cur_tm.tm_min = m;
|
|
|
|
state->cur_tm.tm_sec = s;
|
|
|
|
*when = utc_mktime(&state->cur_tm);
|
2011-08-30 22:22:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-30 23:59:03 +00:00
|
|
|
/* Libdivecomputer: "2011-03-20 10:22:38" */
|
2024-02-28 21:01:51 +00:00
|
|
|
static void divedatetime(const char *buffer, timestamp_t *when, struct parser_state *state)
|
2011-08-30 23:59:03 +00:00
|
|
|
{
|
2014-02-16 23:42:56 +00:00
|
|
|
int y, m, d;
|
|
|
|
int hr, min, sec;
|
2011-08-30 23:59:03 +00:00
|
|
|
|
|
|
|
if (sscanf(buffer, "%d-%d-%d %d:%d:%d",
|
2014-02-16 23:42:56 +00:00
|
|
|
&y, &m, &d, &hr, &min, &sec) == 6) {
|
2018-10-17 16:45:22 +00:00
|
|
|
state->cur_tm.tm_year = y;
|
|
|
|
state->cur_tm.tm_mon = m - 1;
|
|
|
|
state->cur_tm.tm_mday = d;
|
|
|
|
state->cur_tm.tm_hour = hr;
|
|
|
|
state->cur_tm.tm_min = min;
|
|
|
|
state->cur_tm.tm_sec = sec;
|
|
|
|
*when = utc_mktime(&state->cur_tm);
|
2011-08-30 23:59:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-16 23:42:56 +00:00
|
|
|
enum ParseState {
|
|
|
|
FINDSTART,
|
|
|
|
FINDEND
|
|
|
|
};
|
2024-02-28 21:01:51 +00:00
|
|
|
static void divetags(const char *buffer, struct tag_entry **tags)
|
2013-04-09 20:06:30 +00:00
|
|
|
{
|
2013-11-02 01:12:42 +00:00
|
|
|
int i = 0, start = 0, end = 0;
|
|
|
|
enum ParseState state = FINDEND;
|
2013-12-13 00:12:04 +00:00
|
|
|
int len = buffer ? strlen(buffer) : 0;
|
|
|
|
|
2014-02-16 23:42:56 +00:00
|
|
|
while (i < len) {
|
2013-11-02 01:12:42 +00:00
|
|
|
if (buffer[i] == ',') {
|
|
|
|
if (state == FINDSTART) {
|
|
|
|
/* Detect empty tags */
|
|
|
|
} else if (state == FINDEND) {
|
|
|
|
/* Found end of tag */
|
2013-12-13 00:12:04 +00:00
|
|
|
if (i > 0 && buffer[i - 1] != '\\') {
|
2024-02-28 21:01:51 +00:00
|
|
|
std::string s(buffer + start, i - start);
|
2014-02-16 23:42:56 +00:00
|
|
|
state = FINDSTART;
|
2024-02-28 21:01:51 +00:00
|
|
|
taglist_add_tag(tags, s.c_str());
|
2013-11-02 01:12:42 +00:00
|
|
|
} else {
|
2014-02-16 23:42:56 +00:00
|
|
|
state = FINDSTART;
|
2013-04-09 20:06:30 +00:00
|
|
|
}
|
|
|
|
}
|
2013-11-02 01:12:42 +00:00
|
|
|
} else if (buffer[i] == ' ') {
|
|
|
|
/* Handled */
|
|
|
|
} else {
|
|
|
|
/* Found start of tag */
|
|
|
|
if (state == FINDSTART) {
|
|
|
|
state = FINDEND;
|
|
|
|
start = i;
|
|
|
|
} else if (state == FINDEND) {
|
2013-12-13 00:12:04 +00:00
|
|
|
end = i;
|
2013-11-02 01:12:42 +00:00
|
|
|
}
|
2013-04-09 20:06:30 +00:00
|
|
|
}
|
2013-11-02 01:12:42 +00:00
|
|
|
i++;
|
2013-12-11 20:21:52 +00:00
|
|
|
}
|
|
|
|
if (state == FINDEND) {
|
|
|
|
if (end < start)
|
2013-12-13 00:12:04 +00:00
|
|
|
end = len - 1;
|
|
|
|
if (len > 0) {
|
2024-02-28 21:01:51 +00:00
|
|
|
std::string s(buffer + start, i - start);
|
2013-12-13 00:12:04 +00:00
|
|
|
taglist_add_tag(tags, buffer + start);
|
2013-12-11 20:21:52 +00:00
|
|
|
}
|
|
|
|
}
|
2013-04-09 20:06:30 +00:00
|
|
|
}
|
|
|
|
|
2011-08-30 23:23:47 +00:00
|
|
|
enum number_type {
|
|
|
|
NEITHER,
|
2019-08-28 09:21:24 +00:00
|
|
|
FLOATVAL
|
2011-08-30 23:23:47 +00:00
|
|
|
};
|
|
|
|
|
2014-01-08 06:51:22 +00:00
|
|
|
static enum number_type parse_float(const char *buffer, double *res, const char **endp)
|
2011-08-30 23:23:47 +00:00
|
|
|
{
|
2013-02-23 00:18:39 +00:00
|
|
|
double val;
|
2014-01-15 18:54:41 +00:00
|
|
|
static bool first_time = true;
|
2011-08-30 23:23:47 +00:00
|
|
|
|
2013-01-23 20:09:29 +00:00
|
|
|
errno = 0;
|
2013-10-05 07:29:09 +00:00
|
|
|
val = ascii_strtod(buffer, endp);
|
2013-02-23 00:18:39 +00:00
|
|
|
if (errno || *endp == buffer)
|
|
|
|
return NEITHER;
|
2013-03-07 19:43:51 +00:00
|
|
|
if (**endp == ',') {
|
2022-08-30 15:55:43 +00:00
|
|
|
if (nearly_equal(val, rint(val))) {
|
2013-03-07 19:43:51 +00:00
|
|
|
/* we really want to send an error if this is a Subsurface native file
|
|
|
|
* as this is likely indication of a bug - but right now we don't have
|
|
|
|
* that information available */
|
|
|
|
if (first_time) {
|
|
|
|
fprintf(stderr, "Floating point value with decimal comma (%s)?\n", buffer);
|
2014-01-15 18:54:41 +00:00
|
|
|
first_time = false;
|
2013-03-07 19:43:51 +00:00
|
|
|
}
|
2014-01-08 06:51:22 +00:00
|
|
|
/* Try again in permissive mode*/
|
|
|
|
val = strtod_flags(buffer, endp, 0);
|
2013-03-07 19:43:51 +00:00
|
|
|
}
|
|
|
|
}
|
2013-02-23 00:18:39 +00:00
|
|
|
|
|
|
|
*res = val;
|
2019-08-28 09:21:24 +00:00
|
|
|
return FLOATVAL;
|
2013-02-23 00:18:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
union int_or_float {
|
|
|
|
double fp;
|
|
|
|
};
|
2011-08-30 23:23:47 +00:00
|
|
|
|
2024-02-28 21:01:51 +00:00
|
|
|
static enum number_type integer_or_float(const char *buffer, union int_or_float *res)
|
2013-02-23 00:18:39 +00:00
|
|
|
{
|
2014-01-08 06:51:22 +00:00
|
|
|
const char *end;
|
2013-02-23 00:18:39 +00:00
|
|
|
return parse_float(buffer, &res->fp, &end);
|
2011-08-30 23:23:47 +00:00
|
|
|
}
|
|
|
|
|
2024-02-28 21:01:51 +00:00
|
|
|
static void pressure(const char *buffer, pressure_t *pressure, struct parser_state *state)
|
2011-08-30 23:23:47 +00:00
|
|
|
{
|
2013-12-20 17:37:56 +00:00
|
|
|
double mbar = 0.0;
|
2011-08-30 23:23:47 +00:00
|
|
|
union int_or_float val;
|
|
|
|
|
|
|
|
switch (integer_or_float(buffer, &val)) {
|
2019-08-28 09:21:24 +00:00
|
|
|
case FLOATVAL:
|
2011-09-02 21:06:26 +00:00
|
|
|
/* Just ignore zero values */
|
|
|
|
if (!val.fp)
|
|
|
|
break;
|
2018-10-17 16:45:22 +00:00
|
|
|
switch (state->xml_parsing_units.pressure) {
|
2024-02-28 21:01:51 +00:00
|
|
|
case units::PASCALS:
|
2011-09-07 00:01:28 +00:00
|
|
|
mbar = val.fp / 100;
|
|
|
|
break;
|
2024-02-28 21:01:51 +00:00
|
|
|
case units::BAR:
|
2011-09-02 20:59:39 +00:00
|
|
|
/* Assume mbar, but if it's really small, it's bar */
|
|
|
|
mbar = val.fp;
|
2014-07-17 09:00:06 +00:00
|
|
|
if (fabs(mbar) < 5000)
|
2011-09-02 20:59:39 +00:00
|
|
|
mbar = mbar * 1000;
|
|
|
|
break;
|
2024-02-28 21:01:51 +00:00
|
|
|
case units::PSI:
|
2013-11-26 22:11:30 +00:00
|
|
|
mbar = psi_to_mbar(val.fp);
|
2011-08-30 23:23:47 +00:00
|
|
|
break;
|
|
|
|
}
|
2014-07-17 09:00:06 +00:00
|
|
|
if (fabs(mbar) > 5 && fabs(mbar) < 5000000) {
|
2017-03-08 06:41:41 +00:00
|
|
|
pressure->mbar = lrint(mbar);
|
2011-08-30 23:23:47 +00:00
|
|
|
break;
|
|
|
|
}
|
2011-09-02 20:59:39 +00:00
|
|
|
/* fallthrough */
|
2011-08-30 23:23:47 +00:00
|
|
|
default:
|
|
|
|
printf("Strange pressure reading %s\n", buffer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-02-28 21:01:51 +00:00
|
|
|
std::string trimspace(const char *s)
|
|
|
|
{
|
|
|
|
while (isspace(*s))
|
|
|
|
++s;
|
|
|
|
if (!*s)
|
|
|
|
return std::string();
|
|
|
|
const char *end = s + strlen(s);
|
|
|
|
while (isspace(end[-1]))
|
|
|
|
--end;
|
|
|
|
return std::string(s, end - s);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void cylinder_use(const char *buffer, enum cylinderuse *cyl_use, struct parser_state *state)
|
2014-11-16 22:11:34 +00:00
|
|
|
{
|
2024-02-28 21:01:51 +00:00
|
|
|
std::string trimmed = trimspace(buffer);
|
|
|
|
if (!trimmed.empty()) {
|
|
|
|
enum cylinderuse use = cylinderuse_from_text(trimmed.c_str());
|
Start cleaning up sensor indexing for multiple sensors
This is a very timid start at making us actually use multiple sensors
without the magical special case for just CCR oxygen tracking.
It mainly does:
- turn the "sample->sensor" index into an array of two indexes, to
match the pressures themselves.
- get rid of dive->{oxygen_cylinder_index,diluent_cylinder_index},
since a CCR dive should now simply set the sample->sensor[] indices
correctly instead.
- in a couple of places, start actually looping over the sensors rather
than special-case the O2 case (although often the small "loops" are
just unrolled, since it's just two cases.
but in many cases we still end up only covering the zero sensor case,
because the CCR O2 sensor code coverage was fairly limited.
It's entirely possible (even likely) that this migth break some existing
case: it tries to be a fairly direct ("stupid") translation of the old
code, but unlike the preparatory patch this does actually does change
some semantics.
For example, right now the git loader code assumes that if the git save
data contains a o2pressure entry, it just hardcodes the O2 sensor index
to 1.
In fact, one issue is going to simply be that our file formats do not
have that multiple sensor format, but instead had very clearly encoded
things as being the CCR O2 pressure sensor.
But this is hopefully close to usable, and I will need feedback (and
maybe test cases) from people who have existing CCR dives with pressure
data.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-07-21 02:49:45 +00:00
|
|
|
*cyl_use = use;
|
|
|
|
if (use == OXYGEN)
|
2019-08-04 16:44:57 +00:00
|
|
|
state->o2pressure_sensor = state->cur_dive->cylinders.nr - 1;
|
Start cleaning up sensor indexing for multiple sensors
This is a very timid start at making us actually use multiple sensors
without the magical special case for just CCR oxygen tracking.
It mainly does:
- turn the "sample->sensor" index into an array of two indexes, to
match the pressures themselves.
- get rid of dive->{oxygen_cylinder_index,diluent_cylinder_index},
since a CCR dive should now simply set the sample->sensor[] indices
correctly instead.
- in a couple of places, start actually looping over the sensors rather
than special-case the O2 case (although often the small "loops" are
just unrolled, since it's just two cases.
but in many cases we still end up only covering the zero sensor case,
because the CCR O2 sensor code coverage was fairly limited.
It's entirely possible (even likely) that this migth break some existing
case: it tries to be a fairly direct ("stupid") translation of the old
code, but unlike the preparatory patch this does actually does change
some semantics.
For example, right now the git loader code assumes that if the git save
data contains a o2pressure entry, it just hardcodes the O2 sensor index
to 1.
In fact, one issue is going to simply be that our file formats do not
have that multiple sensor format, but instead had very clearly encoded
things as being the CCR O2 pressure sensor.
But this is hopefully close to usable, and I will need feedback (and
maybe test cases) from people who have existing CCR dives with pressure
data.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-07-21 02:49:45 +00:00
|
|
|
}
|
2014-11-16 22:11:34 +00:00
|
|
|
}
|
|
|
|
|
2024-02-28 21:01:51 +00:00
|
|
|
static void salinity(const char *buffer, int *salinity)
|
2012-11-12 19:57:49 +00:00
|
|
|
{
|
|
|
|
union int_or_float val;
|
|
|
|
switch (integer_or_float(buffer, &val)) {
|
2019-08-28 09:21:24 +00:00
|
|
|
case FLOATVAL:
|
2017-03-08 06:41:41 +00:00
|
|
|
*salinity = lrint(val.fp * 10.0);
|
2012-11-12 19:57:49 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
printf("Strange salinity reading %s\n", buffer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-02-28 21:01:51 +00:00
|
|
|
static void depth(const char *buffer, depth_t *depth, struct parser_state *state)
|
2011-08-30 23:23:47 +00:00
|
|
|
{
|
|
|
|
union int_or_float val;
|
|
|
|
|
|
|
|
switch (integer_or_float(buffer, &val)) {
|
2019-08-28 09:21:24 +00:00
|
|
|
case FLOATVAL:
|
2018-10-17 16:45:22 +00:00
|
|
|
switch (state->xml_parsing_units.length) {
|
2024-02-28 21:01:51 +00:00
|
|
|
case units::METERS:
|
2017-03-08 06:41:41 +00:00
|
|
|
depth->mm = lrint(val.fp * 1000);
|
2011-09-02 20:59:39 +00:00
|
|
|
break;
|
2024-02-28 21:01:51 +00:00
|
|
|
case units::FEET:
|
2013-11-26 22:11:30 +00:00
|
|
|
depth->mm = feet_to_mm(val.fp);
|
2011-09-02 20:59:39 +00:00
|
|
|
break;
|
|
|
|
}
|
2011-08-30 23:23:47 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
printf("Strange depth reading %s\n", buffer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-17 16:45:22 +00:00
|
|
|
static void extra_data_start(struct parser_state *state)
|
2014-11-06 18:34:19 +00:00
|
|
|
{
|
2024-03-01 21:53:43 +00:00
|
|
|
state->cur_extra_data.key.clear();
|
|
|
|
state->cur_extra_data.value.clear();
|
2014-11-06 18:34:19 +00:00
|
|
|
}
|
|
|
|
|
2018-10-17 16:45:22 +00:00
|
|
|
static void extra_data_end(struct parser_state *state)
|
2014-11-06 18:34:19 +00:00
|
|
|
{
|
|
|
|
// don't save partial structures - we must have both key and value
|
2024-03-01 21:53:43 +00:00
|
|
|
if (!state->cur_extra_data.key.empty() && !state->cur_extra_data.value.empty())
|
|
|
|
add_extra_data(get_dc(state), state->cur_extra_data.key.c_str(), state->cur_extra_data.value.c_str());
|
2014-11-06 18:34:19 +00:00
|
|
|
}
|
|
|
|
|
2024-02-28 21:01:51 +00:00
|
|
|
static void weight(const char *buffer, weight_t *weight, struct parser_state *state)
|
2011-12-24 03:41:16 +00:00
|
|
|
{
|
|
|
|
union int_or_float val;
|
|
|
|
|
|
|
|
switch (integer_or_float(buffer, &val)) {
|
2019-08-28 09:21:24 +00:00
|
|
|
case FLOATVAL:
|
2018-10-17 16:45:22 +00:00
|
|
|
switch (state->xml_parsing_units.weight) {
|
2024-02-28 21:01:51 +00:00
|
|
|
case units::KG:
|
2017-03-08 06:41:41 +00:00
|
|
|
weight->grams = lrint(val.fp * 1000);
|
2011-12-24 03:41:16 +00:00
|
|
|
break;
|
2024-02-28 21:01:51 +00:00
|
|
|
case units::LBS:
|
2013-11-26 22:11:30 +00:00
|
|
|
weight->grams = lbs_to_grams(val.fp);
|
2011-12-24 03:41:16 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
2012-11-24 10:12:16 +00:00
|
|
|
printf("Strange weight reading %s\n", buffer);
|
2011-12-24 03:41:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-02-28 21:01:51 +00:00
|
|
|
static void temperature(const char *buffer, temperature_t *temperature, struct parser_state *state)
|
2011-08-30 23:23:47 +00:00
|
|
|
{
|
|
|
|
union int_or_float val;
|
|
|
|
|
|
|
|
switch (integer_or_float(buffer, &val)) {
|
2019-08-28 09:21:24 +00:00
|
|
|
case FLOATVAL:
|
2018-10-17 16:45:22 +00:00
|
|
|
switch (state->xml_parsing_units.temperature) {
|
2024-02-28 21:01:51 +00:00
|
|
|
case units::KELVIN:
|
2017-03-09 16:07:30 +00:00
|
|
|
temperature->mkelvin = lrint(val.fp * 1000);
|
2011-09-07 00:01:28 +00:00
|
|
|
break;
|
2024-02-28 21:01:51 +00:00
|
|
|
case units::CELSIUS:
|
2013-11-26 22:11:30 +00:00
|
|
|
temperature->mkelvin = C_to_mkelvin(val.fp);
|
2011-08-30 23:23:47 +00:00
|
|
|
break;
|
2024-02-28 21:01:51 +00:00
|
|
|
case units::FAHRENHEIT:
|
2013-11-26 22:11:30 +00:00
|
|
|
temperature->mkelvin = F_to_mkelvin(val.fp);
|
2011-08-30 23:23:47 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
printf("Strange temperature reading %s\n", buffer);
|
|
|
|
}
|
2013-03-08 19:52:10 +00:00
|
|
|
/* temperatures outside -40C .. +70C should be ignored */
|
|
|
|
if (temperature->mkelvin < ZERO_C_IN_MKELVIN - 40000 ||
|
2014-02-16 23:42:56 +00:00
|
|
|
temperature->mkelvin > ZERO_C_IN_MKELVIN + 70000)
|
2013-03-08 19:52:10 +00:00
|
|
|
temperature->mkelvin = 0;
|
2011-08-30 23:23:47 +00:00
|
|
|
}
|
|
|
|
|
2024-02-28 21:01:51 +00:00
|
|
|
static void sampletime(const char *buffer, duration_t *time)
|
2011-08-30 23:23:47 +00:00
|
|
|
{
|
2011-08-31 00:45:03 +00:00
|
|
|
int i;
|
2018-09-25 22:35:47 +00:00
|
|
|
int hr, min, sec;
|
2011-08-30 23:23:47 +00:00
|
|
|
|
2018-09-25 22:35:47 +00:00
|
|
|
i = sscanf(buffer, "%d:%d:%d", &hr, &min, &sec);
|
2011-08-31 00:45:03 +00:00
|
|
|
switch (i) {
|
|
|
|
case 1:
|
2018-09-25 22:35:47 +00:00
|
|
|
min = hr;
|
|
|
|
hr = 0;
|
2011-08-31 00:45:03 +00:00
|
|
|
/* fallthrough */
|
|
|
|
case 2:
|
2018-09-25 22:35:47 +00:00
|
|
|
sec = min;
|
|
|
|
min = hr;
|
|
|
|
hr = 0;
|
|
|
|
/* fallthrough */
|
|
|
|
case 3:
|
|
|
|
time->seconds = (hr * 60 + min) * 60 + sec;
|
2011-08-30 23:23:47 +00:00
|
|
|
break;
|
|
|
|
default:
|
2019-08-04 21:52:39 +00:00
|
|
|
time->seconds = 0;
|
2011-08-30 23:23:47 +00:00
|
|
|
printf("Strange sample time reading %s\n", buffer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-02-28 21:01:51 +00:00
|
|
|
static void offsettime(const char *buffer, offset_t *time)
|
2014-07-08 19:29:06 +00:00
|
|
|
{
|
|
|
|
duration_t uoffset;
|
|
|
|
int sign = 1;
|
|
|
|
if (*buffer == '-') {
|
|
|
|
sign = -1;
|
|
|
|
buffer++;
|
|
|
|
}
|
|
|
|
/* yes, this could indeed fail if we have an offset > 34yrs
|
|
|
|
* - too bad */
|
|
|
|
sampletime(buffer, &uoffset);
|
|
|
|
time->seconds = sign * uoffset.seconds;
|
|
|
|
}
|
|
|
|
|
2024-02-28 21:01:51 +00:00
|
|
|
static void duration(const char *buffer, duration_t *time)
|
2011-08-31 00:45:03 +00:00
|
|
|
{
|
2013-02-25 22:19:16 +00:00
|
|
|
/* DivingLog 5.08 (and maybe other versions) appear to sometimes
|
|
|
|
* store the dive time as 44.00 instead of 44:00;
|
|
|
|
* This attempts to parse this in a fairly robust way */
|
2014-02-16 23:42:56 +00:00
|
|
|
if (!strchr(buffer, ':') && strchr(buffer, '.')) {
|
2024-02-29 06:56:27 +00:00
|
|
|
std::string mybuffer(buffer);
|
|
|
|
char *dot = strchr(mybuffer.data(), '.');
|
2013-02-25 22:19:16 +00:00
|
|
|
*dot = ':';
|
2024-02-29 06:56:27 +00:00
|
|
|
sampletime(mybuffer.data(), time);
|
2013-02-25 22:19:16 +00:00
|
|
|
} else {
|
Make parse-xml callbacks be type-safe
.. and fix the type breakage brought in by commit eaf6d564874a ("CCR code:
Change to sample structure")
The XML parsing callbacks pass a "void *" around, because the helper
function that matches the XML node names ("match()") does so for all the
different dive/sample/dc member nodes that all have different types.
But that also hid the fact that it very much depended on the various types
being regular "int" etc, rather than the denser types that were introduced
so that the CCR data wouldn't expand memory use excessively. As a result,
XML loading would overwrite other members, and possibly even the
allocation, when it wrote an "int" value to something that only was a
8-bit allocation.
I left the "utf8_string()" without type checking - so it still uses
"void *_res" for the result type, with the cast happening inside the
function.
That's because the result destination ends up being a bit mixed-up wrt
"const char **" and just plain "char **". Note that the thing we modify
itself isn't const (it's not "char *const *"), but the pointer, but we
basically sometimes assign a "const char *", and sometimes a "char *".
I considered making two different versions of the callback, but it just
wasn't worth it. So "utf8_string()" users still aren't type-checked, and
you'd better give it a pointer to something that is some kind of "char *"
This patch doesn't really change the calling convention of the matching
function itself, but it makes the wrapper macro ("MATCH()") take a
properly type-checked function pointer instead (with a dummy call to do
type checking), and then casts the pointer to the "void *" type for the
actual real call.
The function pointer call is not really portable (although it works on
all sane architectures, particularly since the cast only changes one
argument from one type of pointer to another), and to make matters worse
uses the gcc statement-expression extension. But all the compilers we use
seem to support that gcc'ism, so in practice this gives us type-safety
with no downsides.
(If we ever want to use MSVC to compile subsurface, I suspect we'll have
to ifdef out the statement expression use and not type-check things. Or
perhaps re-write the thing as a ternary expression instead, or something).
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-06-07 21:41:07 +00:00
|
|
|
sampletime(buffer, time);
|
2013-02-25 22:19:16 +00:00
|
|
|
}
|
2011-08-31 00:45:03 +00:00
|
|
|
}
|
|
|
|
|
2024-02-28 21:01:51 +00:00
|
|
|
static void percent(const char *buffer, fraction_t *fraction)
|
Start parsing gas mixes
The suunto xml is just completely crazy. What's the helium percentage
companion to "o2pct"? Would it be "hepct"? No. It's "hepct_0".
Ok, so they didn't number the first o2pct, which could be seen as sane:
that's the only mix value that should always exist. And they clearly
started their indexing with 0. So with multiple mixes, you'd then
expect "o2pct_1" and "hepct_1", right?
Wrong! Because XML people are crazy, the second O2 mix percentage is
obviously "o2pct_2". So the O2 percentages are one-based, with an
implicit one. But the He percentages are zero-based with an explicit
zero. So the second mix is "o2pct_2" and "hepct_1".
I'd like to ask what drugs Suunto people are on, but hey, it's a Finnish
company. No need to ask. Vodka explains everything. LOTS AND LOTS OF
VODKA.
In comparison, the libdivecomputer output is nice and sane, and uses a
'gasmix' node. Of course, now we have so many different XML nesting
nodes to check that I just made it an array of different noces. That
also allows me to mark the suunto case, so that we only do the "check
for crazy alcoholic xml entries" when it's a suunto file.
The "type of file" thing is probably a good idea for deciding on default
units too. Some day.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-09-01 20:32:52 +00:00
|
|
|
{
|
2013-02-23 00:18:39 +00:00
|
|
|
double val;
|
2014-01-08 06:51:22 +00:00
|
|
|
const char *end;
|
Start parsing gas mixes
The suunto xml is just completely crazy. What's the helium percentage
companion to "o2pct"? Would it be "hepct"? No. It's "hepct_0".
Ok, so they didn't number the first o2pct, which could be seen as sane:
that's the only mix value that should always exist. And they clearly
started their indexing with 0. So with multiple mixes, you'd then
expect "o2pct_1" and "hepct_1", right?
Wrong! Because XML people are crazy, the second O2 mix percentage is
obviously "o2pct_2". So the O2 percentages are one-based, with an
implicit one. But the He percentages are zero-based with an explicit
zero. So the second mix is "o2pct_2" and "hepct_1".
I'd like to ask what drugs Suunto people are on, but hey, it's a Finnish
company. No need to ask. Vodka explains everything. LOTS AND LOTS OF
VODKA.
In comparison, the libdivecomputer output is nice and sane, and uses a
'gasmix' node. Of course, now we have so many different XML nesting
nodes to check that I just made it an array of different noces. That
also allows me to mark the suunto case, so that we only do the "check
for crazy alcoholic xml entries" when it's a suunto file.
The "type of file" thing is probably a good idea for deciding on default
units too. Some day.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-09-01 20:32:52 +00:00
|
|
|
|
2013-02-23 00:18:39 +00:00
|
|
|
switch (parse_float(buffer, &val, &end)) {
|
2019-08-28 09:21:24 +00:00
|
|
|
case FLOATVAL:
|
2013-02-23 00:18:39 +00:00
|
|
|
/* Turn fractions into percent unless explicit.. */
|
|
|
|
if (val <= 1.0) {
|
2013-10-05 07:29:09 +00:00
|
|
|
while (isspace(*end))
|
2013-02-23 00:18:39 +00:00
|
|
|
end++;
|
|
|
|
if (*end != '%')
|
|
|
|
val *= 100;
|
|
|
|
}
|
Start parsing gas mixes
The suunto xml is just completely crazy. What's the helium percentage
companion to "o2pct"? Would it be "hepct"? No. It's "hepct_0".
Ok, so they didn't number the first o2pct, which could be seen as sane:
that's the only mix value that should always exist. And they clearly
started their indexing with 0. So with multiple mixes, you'd then
expect "o2pct_1" and "hepct_1", right?
Wrong! Because XML people are crazy, the second O2 mix percentage is
obviously "o2pct_2". So the O2 percentages are one-based, with an
implicit one. But the He percentages are zero-based with an explicit
zero. So the second mix is "o2pct_2" and "hepct_1".
I'd like to ask what drugs Suunto people are on, but hey, it's a Finnish
company. No need to ask. Vodka explains everything. LOTS AND LOTS OF
VODKA.
In comparison, the libdivecomputer output is nice and sane, and uses a
'gasmix' node. Of course, now we have so many different XML nesting
nodes to check that I just made it an array of different noces. That
also allows me to mark the suunto case, so that we only do the "check
for crazy alcoholic xml entries" when it's a suunto file.
The "type of file" thing is probably a good idea for deciding on default
units too. Some day.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-09-01 20:32:52 +00:00
|
|
|
|
2013-02-23 00:18:39 +00:00
|
|
|
/* Then turn percent into our integer permille format */
|
|
|
|
if (val >= 0 && val <= 100.0) {
|
2017-03-08 06:41:41 +00:00
|
|
|
fraction->permille = lrint(val * 10);
|
2013-02-23 00:18:39 +00:00
|
|
|
break;
|
|
|
|
}
|
Start parsing gas mixes
The suunto xml is just completely crazy. What's the helium percentage
companion to "o2pct"? Would it be "hepct"? No. It's "hepct_0".
Ok, so they didn't number the first o2pct, which could be seen as sane:
that's the only mix value that should always exist. And they clearly
started their indexing with 0. So with multiple mixes, you'd then
expect "o2pct_1" and "hepct_1", right?
Wrong! Because XML people are crazy, the second O2 mix percentage is
obviously "o2pct_2". So the O2 percentages are one-based, with an
implicit one. But the He percentages are zero-based with an explicit
zero. So the second mix is "o2pct_2" and "hepct_1".
I'd like to ask what drugs Suunto people are on, but hey, it's a Finnish
company. No need to ask. Vodka explains everything. LOTS AND LOTS OF
VODKA.
In comparison, the libdivecomputer output is nice and sane, and uses a
'gasmix' node. Of course, now we have so many different XML nesting
nodes to check that I just made it an array of different noces. That
also allows me to mark the suunto case, so that we only do the "check
for crazy alcoholic xml entries" when it's a suunto file.
The "type of file" thing is probably a good idea for deciding on default
units too. Some day.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-09-01 20:32:52 +00:00
|
|
|
default:
|
2014-02-16 23:42:56 +00:00
|
|
|
printf(translate("gettextFromC", "Strange percentage reading %s\n"), buffer);
|
Start parsing gas mixes
The suunto xml is just completely crazy. What's the helium percentage
companion to "o2pct"? Would it be "hepct"? No. It's "hepct_0".
Ok, so they didn't number the first o2pct, which could be seen as sane:
that's the only mix value that should always exist. And they clearly
started their indexing with 0. So with multiple mixes, you'd then
expect "o2pct_1" and "hepct_1", right?
Wrong! Because XML people are crazy, the second O2 mix percentage is
obviously "o2pct_2". So the O2 percentages are one-based, with an
implicit one. But the He percentages are zero-based with an explicit
zero. So the second mix is "o2pct_2" and "hepct_1".
I'd like to ask what drugs Suunto people are on, but hey, it's a Finnish
company. No need to ask. Vodka explains everything. LOTS AND LOTS OF
VODKA.
In comparison, the libdivecomputer output is nice and sane, and uses a
'gasmix' node. Of course, now we have so many different XML nesting
nodes to check that I just made it an array of different noces. That
also allows me to mark the suunto case, so that we only do the "check
for crazy alcoholic xml entries" when it's a suunto file.
The "type of file" thing is probably a good idea for deciding on default
units too. Some day.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-09-01 20:32:52 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-02-28 21:01:51 +00:00
|
|
|
static void gasmix(const char *buffer, fraction_t *fraction, struct parser_state *state)
|
Start parsing gas mixes
The suunto xml is just completely crazy. What's the helium percentage
companion to "o2pct"? Would it be "hepct"? No. It's "hepct_0".
Ok, so they didn't number the first o2pct, which could be seen as sane:
that's the only mix value that should always exist. And they clearly
started their indexing with 0. So with multiple mixes, you'd then
expect "o2pct_1" and "hepct_1", right?
Wrong! Because XML people are crazy, the second O2 mix percentage is
obviously "o2pct_2". So the O2 percentages are one-based, with an
implicit one. But the He percentages are zero-based with an explicit
zero. So the second mix is "o2pct_2" and "hepct_1".
I'd like to ask what drugs Suunto people are on, but hey, it's a Finnish
company. No need to ask. Vodka explains everything. LOTS AND LOTS OF
VODKA.
In comparison, the libdivecomputer output is nice and sane, and uses a
'gasmix' node. Of course, now we have so many different XML nesting
nodes to check that I just made it an array of different noces. That
also allows me to mark the suunto case, so that we only do the "check
for crazy alcoholic xml entries" when it's a suunto file.
The "type of file" thing is probably a good idea for deciding on default
units too. Some day.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-09-01 20:32:52 +00:00
|
|
|
{
|
2011-09-01 20:46:24 +00:00
|
|
|
/* libdivecomputer does negative percentages. */
|
|
|
|
if (*buffer == '-')
|
|
|
|
return;
|
2019-08-04 16:44:57 +00:00
|
|
|
percent(buffer, fraction);
|
Start parsing gas mixes
The suunto xml is just completely crazy. What's the helium percentage
companion to "o2pct"? Would it be "hepct"? No. It's "hepct_0".
Ok, so they didn't number the first o2pct, which could be seen as sane:
that's the only mix value that should always exist. And they clearly
started their indexing with 0. So with multiple mixes, you'd then
expect "o2pct_1" and "hepct_1", right?
Wrong! Because XML people are crazy, the second O2 mix percentage is
obviously "o2pct_2". So the O2 percentages are one-based, with an
implicit one. But the He percentages are zero-based with an explicit
zero. So the second mix is "o2pct_2" and "hepct_1".
I'd like to ask what drugs Suunto people are on, but hey, it's a Finnish
company. No need to ask. Vodka explains everything. LOTS AND LOTS OF
VODKA.
In comparison, the libdivecomputer output is nice and sane, and uses a
'gasmix' node. Of course, now we have so many different XML nesting
nodes to check that I just made it an array of different noces. That
also allows me to mark the suunto case, so that we only do the "check
for crazy alcoholic xml entries" when it's a suunto file.
The "type of file" thing is probably a good idea for deciding on default
units too. Some day.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-09-01 20:32:52 +00:00
|
|
|
}
|
|
|
|
|
2024-02-28 21:01:51 +00:00
|
|
|
static void gasmix_nitrogen(const char *, struct gasmix *)
|
2011-09-01 23:26:11 +00:00
|
|
|
{
|
|
|
|
/* Ignore n2 percentages. There's no value in them. */
|
|
|
|
}
|
Start parsing gas mixes
The suunto xml is just completely crazy. What's the helium percentage
companion to "o2pct"? Would it be "hepct"? No. It's "hepct_0".
Ok, so they didn't number the first o2pct, which could be seen as sane:
that's the only mix value that should always exist. And they clearly
started their indexing with 0. So with multiple mixes, you'd then
expect "o2pct_1" and "hepct_1", right?
Wrong! Because XML people are crazy, the second O2 mix percentage is
obviously "o2pct_2". So the O2 percentages are one-based, with an
implicit one. But the He percentages are zero-based with an explicit
zero. So the second mix is "o2pct_2" and "hepct_1".
I'd like to ask what drugs Suunto people are on, but hey, it's a Finnish
company. No need to ask. Vodka explains everything. LOTS AND LOTS OF
VODKA.
In comparison, the libdivecomputer output is nice and sane, and uses a
'gasmix' node. Of course, now we have so many different XML nesting
nodes to check that I just made it an array of different noces. That
also allows me to mark the suunto case, so that we only do the "check
for crazy alcoholic xml entries" when it's a suunto file.
The "type of file" thing is probably a good idea for deciding on default
units too. Some day.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-09-01 20:32:52 +00:00
|
|
|
|
2024-02-28 21:01:51 +00:00
|
|
|
static void cylindersize(const char *buffer, volume_t *volume)
|
2011-09-04 03:31:18 +00:00
|
|
|
{
|
|
|
|
union int_or_float val;
|
|
|
|
|
|
|
|
switch (integer_or_float(buffer, &val)) {
|
2019-08-28 09:21:24 +00:00
|
|
|
case FLOATVAL:
|
2017-03-08 06:41:41 +00:00
|
|
|
volume->mliter = lrint(val.fp * 1000);
|
2011-09-04 03:31:18 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
printf("Strange volume reading %s\n", buffer);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-02-28 21:01:51 +00:00
|
|
|
static void event_name(const char *buffer, char *name)
|
2014-08-17 18:26:21 +00:00
|
|
|
{
|
2024-02-28 21:01:51 +00:00
|
|
|
std::string trimmed = trimspace(buffer);
|
|
|
|
size_t size = std::min(trimmed.size(), (size_t)MAX_EVENT_NAME);
|
|
|
|
memcpy(name, trimmed.data(), size);
|
2014-08-17 18:26:21 +00:00
|
|
|
name[size] = 0;
|
|
|
|
}
|
|
|
|
|
2015-09-03 20:25:00 +00:00
|
|
|
// We don't use gauge as a mode, and pscr doesn't exist as a libdc divemode
|
2024-02-28 21:01:51 +00:00
|
|
|
static const char *libdc_divemode_text[] = { "oc", "cc", "pscr", "freedive", "gauge"};
|
2015-09-03 20:25:00 +00:00
|
|
|
|
2014-06-11 17:48:48 +00:00
|
|
|
/* Extract the dive computer type from the xml text buffer */
|
2024-02-28 21:01:51 +00:00
|
|
|
static void get_dc_type(const char *buffer, enum divemode_t *dct)
|
|
|
|
{
|
|
|
|
std::string trimmed = trimspace(buffer);
|
|
|
|
if (!trimmed.empty()) {
|
|
|
|
for (int i = 0; i < NUM_DIVEMODE; i++) {
|
|
|
|
if (trimmed == divemode_text[i]) {
|
|
|
|
*dct = (divemode_t)i;
|
|
|
|
break;
|
|
|
|
} else if (trimmed == libdc_divemode_text[i]) {
|
|
|
|
*dct = (divemode_t)i;
|
|
|
|
break;
|
|
|
|
}
|
2014-11-16 23:11:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-06-11 17:48:48 +00:00
|
|
|
|
2018-04-07 12:56:37 +00:00
|
|
|
/* For divemode_text[] (defined in dive.h) determine the index of
|
|
|
|
* the string contained in the xml divemode attribute and passed
|
|
|
|
* in buffer, below. Typical xml input would be:
|
|
|
|
* <event name='modechange' divemode='OC' /> */
|
2024-02-28 21:01:51 +00:00
|
|
|
static void event_divemode(const char *buffer, int *value)
|
2018-04-07 12:56:37 +00:00
|
|
|
{
|
2024-02-28 21:01:51 +00:00
|
|
|
std::string trimmed = trimspace(buffer);
|
2018-05-08 14:24:51 +00:00
|
|
|
for (int i = 0; i < NUM_DIVEMODE; i++) {
|
2024-02-28 21:01:51 +00:00
|
|
|
if (trimmed == divemode_text[i]) {
|
2018-04-07 12:56:37 +00:00
|
|
|
*value = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-19 14:25:36 +00:00
|
|
|
/* Compare a pattern with a name, whereby the name may end in '\0' or '.'. */
|
|
|
|
static int match_name(const char *pattern, const char *name)
|
|
|
|
{
|
|
|
|
while (*pattern == *name && *pattern) {
|
|
|
|
pattern++;
|
|
|
|
name++;
|
|
|
|
}
|
|
|
|
return *pattern == '\0' && (*name == '\0' || *name == '.');
|
|
|
|
}
|
|
|
|
|
2024-02-28 21:01:51 +00:00
|
|
|
typedef void (*matchfn_t)(const char *buffer, void *);
|
2018-08-19 14:25:36 +00:00
|
|
|
static int match(const char *pattern, const char *name,
|
2018-08-19 14:12:16 +00:00
|
|
|
matchfn_t fn, char *buf, void *data)
|
|
|
|
{
|
2018-08-19 14:25:36 +00:00
|
|
|
if (!match_name(pattern, name))
|
2018-08-19 14:12:16 +00:00
|
|
|
return 0;
|
|
|
|
fn(buf, data);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2024-02-28 21:01:51 +00:00
|
|
|
typedef void (*matchfn_state_t)(const char *buffer, void *, struct parser_state *state);
|
2018-10-17 16:45:22 +00:00
|
|
|
static int match_state(const char *pattern, const char *name,
|
|
|
|
matchfn_state_t fn, char *buf, void *data, struct parser_state *state)
|
|
|
|
{
|
|
|
|
if (!match_name(pattern, name))
|
|
|
|
return 0;
|
|
|
|
fn(buf, data, state);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
Make parse-xml callbacks be type-safe
.. and fix the type breakage brought in by commit eaf6d564874a ("CCR code:
Change to sample structure")
The XML parsing callbacks pass a "void *" around, because the helper
function that matches the XML node names ("match()") does so for all the
different dive/sample/dc member nodes that all have different types.
But that also hid the fact that it very much depended on the various types
being regular "int" etc, rather than the denser types that were introduced
so that the CCR data wouldn't expand memory use excessively. As a result,
XML loading would overwrite other members, and possibly even the
allocation, when it wrote an "int" value to something that only was a
8-bit allocation.
I left the "utf8_string()" without type checking - so it still uses
"void *_res" for the result type, with the cast happening inside the
function.
That's because the result destination ends up being a bit mixed-up wrt
"const char **" and just plain "char **". Note that the thing we modify
itself isn't const (it's not "char *const *"), but the pointer, but we
basically sometimes assign a "const char *", and sometimes a "char *".
I considered making two different versions of the callback, but it just
wasn't worth it. So "utf8_string()" users still aren't type-checked, and
you'd better give it a pointer to something that is some kind of "char *"
This patch doesn't really change the calling convention of the matching
function itself, but it makes the wrapper macro ("MATCH()") take a
properly type-checked function pointer instead (with a dummy call to do
type checking), and then casts the pointer to the "void *" type for the
actual real call.
The function pointer call is not really portable (although it works on
all sane architectures, particularly since the cast only changes one
argument from one type of pointer to another), and to make matters worse
uses the gcc statement-expression extension. But all the compilers we use
seem to support that gcc'ism, so in practice this gives us type-safety
with no downsides.
(If we ever want to use MSVC to compile subsurface, I suspect we'll have
to ifdef out the statement expression use and not type-check things. Or
perhaps re-write the thing as a ternary expression instead, or something).
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-06-07 21:41:07 +00:00
|
|
|
#define MATCH(pattern, fn, dest) ({ \
|
|
|
|
/* Silly type compatibility test */ \
|
|
|
|
if (0) (fn)("test", dest); \
|
2018-08-19 14:25:36 +00:00
|
|
|
match(pattern, name, (matchfn_t) (fn), buf, dest); })
|
2011-09-01 18:22:05 +00:00
|
|
|
|
2018-10-17 16:45:22 +00:00
|
|
|
#define MATCH_STATE(pattern, fn, dest) ({ \
|
|
|
|
/* Silly type compatibility test */ \
|
|
|
|
if (0) (fn)("test", dest, state); \
|
|
|
|
match_state(pattern, name, (matchfn_state_t) (fn), buf, dest, state); })
|
|
|
|
|
2024-02-28 21:01:51 +00:00
|
|
|
static void get_index(const char *buffer, int *i)
|
2011-09-02 22:01:53 +00:00
|
|
|
{
|
|
|
|
*i = atoi(buffer);
|
|
|
|
}
|
|
|
|
|
2024-02-28 21:01:51 +00:00
|
|
|
static void get_bool(const char *buffer, bool *i)
|
2018-01-04 14:47:12 +00:00
|
|
|
{
|
|
|
|
*i = atoi(buffer);
|
|
|
|
}
|
|
|
|
|
2024-02-28 21:01:51 +00:00
|
|
|
static void get_uint8(const char *buffer, uint8_t *i)
|
Make parse-xml callbacks be type-safe
.. and fix the type breakage brought in by commit eaf6d564874a ("CCR code:
Change to sample structure")
The XML parsing callbacks pass a "void *" around, because the helper
function that matches the XML node names ("match()") does so for all the
different dive/sample/dc member nodes that all have different types.
But that also hid the fact that it very much depended on the various types
being regular "int" etc, rather than the denser types that were introduced
so that the CCR data wouldn't expand memory use excessively. As a result,
XML loading would overwrite other members, and possibly even the
allocation, when it wrote an "int" value to something that only was a
8-bit allocation.
I left the "utf8_string()" without type checking - so it still uses
"void *_res" for the result type, with the cast happening inside the
function.
That's because the result destination ends up being a bit mixed-up wrt
"const char **" and just plain "char **". Note that the thing we modify
itself isn't const (it's not "char *const *"), but the pointer, but we
basically sometimes assign a "const char *", and sometimes a "char *".
I considered making two different versions of the callback, but it just
wasn't worth it. So "utf8_string()" users still aren't type-checked, and
you'd better give it a pointer to something that is some kind of "char *"
This patch doesn't really change the calling convention of the matching
function itself, but it makes the wrapper macro ("MATCH()") take a
properly type-checked function pointer instead (with a dummy call to do
type checking), and then casts the pointer to the "void *" type for the
actual real call.
The function pointer call is not really portable (although it works on
all sane architectures, particularly since the cast only changes one
argument from one type of pointer to another), and to make matters worse
uses the gcc statement-expression extension. But all the compilers we use
seem to support that gcc'ism, so in practice this gives us type-safety
with no downsides.
(If we ever want to use MSVC to compile subsurface, I suspect we'll have
to ifdef out the statement expression use and not type-check things. Or
perhaps re-write the thing as a ternary expression instead, or something).
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-06-07 21:41:07 +00:00
|
|
|
{
|
|
|
|
*i = atoi(buffer);
|
|
|
|
}
|
|
|
|
|
2024-02-28 21:01:51 +00:00
|
|
|
static void get_uint16(const char *buffer, uint16_t *i)
|
2017-11-10 09:24:32 +00:00
|
|
|
{
|
|
|
|
*i = atoi(buffer);
|
|
|
|
}
|
|
|
|
|
2024-02-28 21:01:51 +00:00
|
|
|
static void get_bearing(const char *buffer, bearing_t *bearing)
|
Make parse-xml callbacks be type-safe
.. and fix the type breakage brought in by commit eaf6d564874a ("CCR code:
Change to sample structure")
The XML parsing callbacks pass a "void *" around, because the helper
function that matches the XML node names ("match()") does so for all the
different dive/sample/dc member nodes that all have different types.
But that also hid the fact that it very much depended on the various types
being regular "int" etc, rather than the denser types that were introduced
so that the CCR data wouldn't expand memory use excessively. As a result,
XML loading would overwrite other members, and possibly even the
allocation, when it wrote an "int" value to something that only was a
8-bit allocation.
I left the "utf8_string()" without type checking - so it still uses
"void *_res" for the result type, with the cast happening inside the
function.
That's because the result destination ends up being a bit mixed-up wrt
"const char **" and just plain "char **". Note that the thing we modify
itself isn't const (it's not "char *const *"), but the pointer, but we
basically sometimes assign a "const char *", and sometimes a "char *".
I considered making two different versions of the callback, but it just
wasn't worth it. So "utf8_string()" users still aren't type-checked, and
you'd better give it a pointer to something that is some kind of "char *"
This patch doesn't really change the calling convention of the matching
function itself, but it makes the wrapper macro ("MATCH()") take a
properly type-checked function pointer instead (with a dummy call to do
type checking), and then casts the pointer to the "void *" type for the
actual real call.
The function pointer call is not really portable (although it works on
all sane architectures, particularly since the cast only changes one
argument from one type of pointer to another), and to make matters worse
uses the gcc statement-expression extension. But all the compilers we use
seem to support that gcc'ism, so in practice this gives us type-safety
with no downsides.
(If we ever want to use MSVC to compile subsurface, I suspect we'll have
to ifdef out the statement expression use and not type-check things. Or
perhaps re-write the thing as a ternary expression instead, or something).
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-06-07 21:41:07 +00:00
|
|
|
{
|
|
|
|
bearing->degrees = atoi(buffer);
|
|
|
|
}
|
|
|
|
|
2024-02-28 21:01:51 +00:00
|
|
|
static void get_rating(const char *buffer, int *i)
|
2013-01-29 21:30:02 +00:00
|
|
|
{
|
|
|
|
int j = atoi(buffer);
|
|
|
|
if (j >= 0 && j <= 5) {
|
|
|
|
*i = j;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-02-28 21:01:51 +00:00
|
|
|
static void double_to_o2pressure(const char *buffer, o2pressure_t *i)
|
2012-12-08 04:08:29 +00:00
|
|
|
{
|
2017-03-08 06:41:41 +00:00
|
|
|
i->mbar = lrint(ascii_strtod(buffer, NULL) * 1000.0);
|
2012-12-08 04:08:29 +00:00
|
|
|
}
|
|
|
|
|
2024-02-28 21:01:51 +00:00
|
|
|
static void hex_value(const char *buffer, uint32_t *i)
|
2012-11-25 19:44:27 +00:00
|
|
|
{
|
2013-11-22 21:31:52 +00:00
|
|
|
*i = strtoul(buffer, NULL, 16);
|
2012-11-25 19:44:27 +00:00
|
|
|
}
|
|
|
|
|
2024-02-28 21:01:51 +00:00
|
|
|
static void dive_site(const char *buffer, struct dive *d, struct parser_state *state)
|
2018-10-26 15:03:54 +00:00
|
|
|
{
|
|
|
|
uint32_t uuid;
|
|
|
|
hex_value(buffer, &uuid);
|
2022-11-12 07:57:56 +00:00
|
|
|
add_dive_to_dive_site(d, get_dive_site_by_uuid(uuid, state->log->sites));
|
2018-10-26 15:03:54 +00:00
|
|
|
}
|
|
|
|
|
2024-02-28 21:01:51 +00:00
|
|
|
static void get_notrip(const char *buffer, bool *notrip)
|
2012-08-22 05:04:24 +00:00
|
|
|
{
|
2018-11-18 10:15:32 +00:00
|
|
|
*notrip = !strcmp(buffer, "NOTRIP");
|
2012-08-22 05:04:24 +00:00
|
|
|
}
|
|
|
|
|
2011-09-05 21:29:08 +00:00
|
|
|
/*
|
|
|
|
* Divinglog is crazy. The temperatures are in celsius. EXCEPT
|
|
|
|
* for the sample temperatures, that are in Fahrenheit.
|
|
|
|
* WTF?
|
2011-09-11 20:16:23 +00:00
|
|
|
*
|
|
|
|
* Oh, and I think Diving Log *internally* probably kept them
|
|
|
|
* in celsius, because I'm seeing entries like
|
|
|
|
*
|
|
|
|
* <Temp>32.0</Temp>
|
|
|
|
*
|
|
|
|
* in there. Which is freezing, aka 0 degC. I bet the "0" is
|
|
|
|
* what Diving Log uses for "no temperature".
|
|
|
|
*
|
|
|
|
* So throw away crap like that.
|
2012-10-10 09:14:55 +00:00
|
|
|
*
|
|
|
|
* It gets worse. Sometimes the sample temperatures are in
|
|
|
|
* Celsius, which apparently happens if you are in a SI
|
|
|
|
* locale. So we now do:
|
|
|
|
*
|
|
|
|
* - temperatures < 32.0 == Celsius
|
|
|
|
* - temperature == 32.0 -> garbage, it's a missing temperature (zero converted from C to F)
|
|
|
|
* - temperatures > 32.0 == Fahrenheit
|
2011-09-05 21:29:08 +00:00
|
|
|
*/
|
2024-02-28 21:01:51 +00:00
|
|
|
static void fahrenheit(const char *buffer, temperature_t *temperature)
|
2011-09-05 21:29:08 +00:00
|
|
|
{
|
|
|
|
union int_or_float val;
|
|
|
|
|
|
|
|
switch (integer_or_float(buffer, &val)) {
|
2019-08-28 09:21:24 +00:00
|
|
|
case FLOATVAL:
|
2022-08-30 15:55:43 +00:00
|
|
|
if (nearly_equal(val.fp, 32.0))
|
2011-09-11 20:16:23 +00:00
|
|
|
break;
|
2012-10-10 09:14:55 +00:00
|
|
|
if (val.fp < 32.0)
|
|
|
|
temperature->mkelvin = C_to_mkelvin(val.fp);
|
|
|
|
else
|
|
|
|
temperature->mkelvin = F_to_mkelvin(val.fp);
|
2011-09-05 21:29:08 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
fprintf(stderr, "Crazy Diving Log temperature reading %s\n", buffer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-11 19:24:57 +00:00
|
|
|
/*
|
|
|
|
* Did I mention how bat-shit crazy divinglog is? The sample
|
|
|
|
* pressures are in PSI. But the tank working pressure is in
|
|
|
|
* bar. WTF^2?
|
|
|
|
*
|
2011-09-15 16:43:14 +00:00
|
|
|
* Crazy stuff like this is why subsurface has everything in
|
2011-09-11 19:24:57 +00:00
|
|
|
* these inconvenient typed structures, and you have to say
|
|
|
|
* "pressure->mbar" to get the actual value. Exactly so that
|
|
|
|
* you can never have unit confusion.
|
2012-10-10 09:14:55 +00:00
|
|
|
*
|
|
|
|
* It gets worse: sometimes apparently the pressures are in
|
|
|
|
* bar, sometimes in psi. Dirk suspects that this may be a
|
|
|
|
* DivingLog Uemis importer bug, and that they are always
|
|
|
|
* supposed to be in bar, but that the importer got the
|
|
|
|
* sample importing wrong.
|
|
|
|
*
|
|
|
|
* Sadly, there's no way to really tell. So I think we just
|
|
|
|
* have to have some arbitrary cut-off point where we assume
|
|
|
|
* that smaller values mean bar.. Not good.
|
2011-09-11 19:24:57 +00:00
|
|
|
*/
|
2024-02-28 21:01:51 +00:00
|
|
|
static void psi_or_bar(const char *buffer, pressure_t *pressure)
|
2011-09-11 19:24:57 +00:00
|
|
|
{
|
|
|
|
union int_or_float val;
|
|
|
|
|
|
|
|
switch (integer_or_float(buffer, &val)) {
|
2019-08-28 09:21:24 +00:00
|
|
|
case FLOATVAL:
|
2012-10-10 09:14:55 +00:00
|
|
|
if (val.fp > 400)
|
|
|
|
pressure->mbar = psi_to_mbar(val.fp);
|
|
|
|
else
|
2017-03-08 06:41:41 +00:00
|
|
|
pressure->mbar = lrint(val.fp * 1000);
|
2011-09-11 19:24:57 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
fprintf(stderr, "Crazy Diving Log PSI reading %s\n", buffer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-17 16:45:22 +00:00
|
|
|
static int divinglog_fill_sample(struct sample *sample, const char *name, char *buf, struct parser_state *state)
|
2011-09-05 21:29:08 +00:00
|
|
|
{
|
2014-02-16 23:42:56 +00:00
|
|
|
return MATCH("time.p", sampletime, &sample->time) ||
|
2018-10-17 16:45:22 +00:00
|
|
|
MATCH_STATE("depth.p", depth, &sample->depth) ||
|
2014-02-16 23:42:56 +00:00
|
|
|
MATCH("temp.p", fahrenheit, &sample->temperature) ||
|
2017-07-20 21:39:02 +00:00
|
|
|
MATCH("press1.p", psi_or_bar, &sample->pressure[0]) ||
|
2014-02-16 23:42:56 +00:00
|
|
|
0;
|
2011-09-05 21:29:08 +00:00
|
|
|
}
|
|
|
|
|
2024-02-28 21:01:51 +00:00
|
|
|
static void uddf_gasswitch(const char *buffer, struct sample *sample, struct parser_state *state)
|
2013-02-22 16:52:35 +00:00
|
|
|
{
|
|
|
|
int idx = atoi(buffer);
|
|
|
|
int seconds = sample->time.seconds;
|
2018-10-17 16:45:22 +00:00
|
|
|
struct dive *dive = state->cur_dive;
|
|
|
|
struct divecomputer *dc = get_dc(state);
|
2013-02-22 16:52:35 +00:00
|
|
|
|
|
|
|
add_gas_switch_event(dive, dc, seconds, idx);
|
|
|
|
}
|
|
|
|
|
2018-10-17 16:45:22 +00:00
|
|
|
static int uddf_fill_sample(struct sample *sample, const char *name, char *buf, struct parser_state *state)
|
2011-09-07 00:33:52 +00:00
|
|
|
{
|
2014-02-16 23:42:56 +00:00
|
|
|
return MATCH("divetime", sampletime, &sample->time) ||
|
2018-10-17 16:45:22 +00:00
|
|
|
MATCH_STATE("depth", depth, &sample->depth) ||
|
|
|
|
MATCH_STATE("temperature", temperature, &sample->temperature) ||
|
|
|
|
MATCH_STATE("tankpressure", pressure, &sample->pressure[0]) ||
|
|
|
|
MATCH_STATE("ref.switchmix", uddf_gasswitch, sample) ||
|
2014-02-16 23:42:56 +00:00
|
|
|
0;
|
2011-09-07 00:33:52 +00:00
|
|
|
}
|
|
|
|
|
2024-02-28 21:01:51 +00:00
|
|
|
static void eventtime(const char *buffer, duration_t *duration, struct parser_state *state)
|
2011-09-23 01:02:54 +00:00
|
|
|
{
|
|
|
|
sampletime(buffer, duration);
|
2018-10-17 16:45:22 +00:00
|
|
|
if (state->cur_sample)
|
|
|
|
duration->seconds += state->cur_sample->time.seconds;
|
2011-09-23 01:02:54 +00:00
|
|
|
}
|
|
|
|
|
2022-11-12 08:14:00 +00:00
|
|
|
static void try_to_match_autogroup(const char *name, char *buf, struct parser_state *state)
|
2013-01-02 01:29:38 +00:00
|
|
|
{
|
2022-11-12 08:14:00 +00:00
|
|
|
bool autogroup;
|
2013-01-02 01:29:38 +00:00
|
|
|
|
|
|
|
start_match("autogroup", name, buf);
|
2022-11-12 08:14:00 +00:00
|
|
|
if (MATCH("state.autogroup", get_bool, &autogroup)) {
|
|
|
|
state->log->autogroup = autogroup;
|
2013-01-02 01:29:38 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
nonmatch("autogroup", name, buf);
|
|
|
|
}
|
|
|
|
|
2024-02-28 21:01:51 +00:00
|
|
|
static void get_cylinderindex(const char *buffer, int16_t *i, struct parser_state *state)
|
2014-06-11 17:48:48 +00:00
|
|
|
{
|
|
|
|
*i = atoi(buffer);
|
2018-10-17 16:45:22 +00:00
|
|
|
if (state->lastcylinderindex != *i) {
|
|
|
|
add_gas_switch_event(state->cur_dive, get_dc(state), state->cur_sample->time.seconds, *i);
|
|
|
|
state->lastcylinderindex = *i;
|
2014-06-11 17:48:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-02-28 21:01:51 +00:00
|
|
|
static void get_sensor(const char *buffer, int16_t *i)
|
2014-06-11 17:48:48 +00:00
|
|
|
{
|
|
|
|
*i = atoi(buffer);
|
|
|
|
}
|
|
|
|
|
2024-02-28 21:01:51 +00:00
|
|
|
static void parse_libdc_deco(const char *buffer, struct sample *s)
|
2015-09-03 20:25:00 +00:00
|
|
|
{
|
|
|
|
if (strcmp(buffer, "deco") == 0) {
|
|
|
|
s->in_deco = true;
|
|
|
|
} else if (strcmp(buffer, "ndl") == 0) {
|
|
|
|
s->in_deco = false;
|
|
|
|
// The time wasn't stoptime, it was ndl
|
|
|
|
s->ndl = s->stoptime;
|
|
|
|
s->stoptime.seconds = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-17 16:45:22 +00:00
|
|
|
static void try_to_fill_dc_settings(const char *name, char *buf, struct parser_state *state)
|
2012-12-26 21:47:54 +00:00
|
|
|
{
|
|
|
|
start_match("divecomputerid", name, buf);
|
2024-02-29 06:56:27 +00:00
|
|
|
if (MATCH("model.divecomputerid", utf8_string_std, &state->cur_settings.dc.model))
|
2012-12-26 21:47:54 +00:00
|
|
|
return;
|
2018-10-17 16:45:22 +00:00
|
|
|
if (MATCH("deviceid.divecomputerid", hex_value, &state->cur_settings.dc.deviceid))
|
2012-12-26 21:47:54 +00:00
|
|
|
return;
|
2024-02-29 06:56:27 +00:00
|
|
|
if (MATCH("nickname.divecomputerid", utf8_string_std, &state->cur_settings.dc.nickname))
|
2012-12-26 21:47:54 +00:00
|
|
|
return;
|
2024-02-29 06:56:27 +00:00
|
|
|
if (MATCH("serial.divecomputerid", utf8_string_std, &state->cur_settings.dc.serial_nr))
|
Assemble the actual Suunto serial number
It turns out that the serial number returned by libdivecomputer isn't
really the serial number as interpreted by the vendor. Those tend to be
strings, but libdivecomputer gives us a 32bit number.
Some experimenting showed that for the Suunto devies tested the serial
number is encoded in that 32bit number:
It so happens that the Suunto serial number strings are strings that have
all numbers, but they aren't *one* number. They are four bytes
representing two numbers each, and the "23500027" string is actually the
four bytes 23 50 00 27 (0x17 0x32 0x00 0x1b). And libdivecomputer has
incorrectly parsed those four bytes as one number, not as the encoded
serial number string it is. So the value 389152795 is actually hex
0x1732001b, which is 0x17 0x32 0x00 0x1b, which is - 23 50 00 27.
This should be done by libdivecomputer, but hey, in the meantime this at
least shows the concept. And helps test the XML save/restore code.
It depends on the two patches that create the whole "device.c"
infrastructure, of course. With this, my dive file ends up having the
settings section look like this:
<divecomputerid model='Suunto Vyper Air' deviceid='d4629110'
serial='01201094' firmware='1.1.22'/>
<divecomputerid model='Suunto HelO2' deviceid='995dd566'
serial='23500027' firmware='1.0.4'/>
where the format of the firmware version is something I guessed at,
but it was the obvious choice (again, it's byte-based, I'm ignoring
the high byte that is zero for both of my Suuntos).
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-10 00:14:21 +00:00
|
|
|
return;
|
2024-02-29 06:56:27 +00:00
|
|
|
if (MATCH("firmware.divecomputerid", utf8_string_std, &state->cur_settings.dc.firmware))
|
Assemble the actual Suunto serial number
It turns out that the serial number returned by libdivecomputer isn't
really the serial number as interpreted by the vendor. Those tend to be
strings, but libdivecomputer gives us a 32bit number.
Some experimenting showed that for the Suunto devies tested the serial
number is encoded in that 32bit number:
It so happens that the Suunto serial number strings are strings that have
all numbers, but they aren't *one* number. They are four bytes
representing two numbers each, and the "23500027" string is actually the
four bytes 23 50 00 27 (0x17 0x32 0x00 0x1b). And libdivecomputer has
incorrectly parsed those four bytes as one number, not as the encoded
serial number string it is. So the value 389152795 is actually hex
0x1732001b, which is 0x17 0x32 0x00 0x1b, which is - 23 50 00 27.
This should be done by libdivecomputer, but hey, in the meantime this at
least shows the concept. And helps test the XML save/restore code.
It depends on the two patches that create the whole "device.c"
infrastructure, of course. With this, my dive file ends up having the
settings section look like this:
<divecomputerid model='Suunto Vyper Air' deviceid='d4629110'
serial='01201094' firmware='1.1.22'/>
<divecomputerid model='Suunto HelO2' deviceid='995dd566'
serial='23500027' firmware='1.0.4'/>
where the format of the firmware version is something I guessed at,
but it was the obvious choice (again, it's byte-based, I'm ignoring
the high byte that is zero for both of my Suuntos).
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-10 00:14:21 +00:00
|
|
|
return;
|
2012-12-26 21:47:54 +00:00
|
|
|
|
|
|
|
nonmatch("divecomputerid", name, buf);
|
|
|
|
}
|
|
|
|
|
2021-10-30 23:31:29 +00:00
|
|
|
static void try_to_fill_fingerprint(const char *name, char *buf, struct parser_state *state)
|
|
|
|
{
|
|
|
|
start_match("fingerprint", name, buf);
|
|
|
|
if (MATCH("model.fingerprint", hex_value, &state->cur_settings.fingerprint.model))
|
|
|
|
return;
|
|
|
|
if (MATCH("serial.fingerprint", hex_value, &state->cur_settings.fingerprint.serial))
|
|
|
|
return;
|
|
|
|
if (MATCH("deviceid.fingerprint", hex_value, &state->cur_settings.fingerprint.fdeviceid))
|
|
|
|
return;
|
|
|
|
if (MATCH("diveid.fingerprint", hex_value, &state->cur_settings.fingerprint.fdiveid))
|
|
|
|
return;
|
2024-02-29 06:56:27 +00:00
|
|
|
if (MATCH("data.fingerprint", utf8_string_std, &state->cur_settings.fingerprint.data))
|
2021-10-30 23:31:29 +00:00
|
|
|
return;
|
|
|
|
nonmatch("fingerprint", name, buf);
|
|
|
|
}
|
|
|
|
|
2018-10-17 16:45:22 +00:00
|
|
|
static void try_to_fill_event(const char *name, char *buf, struct parser_state *state)
|
2011-09-23 01:02:54 +00:00
|
|
|
{
|
|
|
|
start_match("event", name, buf);
|
2018-10-17 16:45:22 +00:00
|
|
|
if (MATCH("event", event_name, state->cur_event.name))
|
2011-09-23 01:02:54 +00:00
|
|
|
return;
|
2018-10-17 16:45:22 +00:00
|
|
|
if (MATCH("name", event_name, state->cur_event.name))
|
2011-09-23 01:02:54 +00:00
|
|
|
return;
|
2018-10-17 16:45:22 +00:00
|
|
|
if (MATCH_STATE("time", eventtime, &state->cur_event.time))
|
2011-09-23 01:02:54 +00:00
|
|
|
return;
|
2018-10-17 16:45:22 +00:00
|
|
|
if (MATCH("type", get_index, &state->cur_event.type))
|
2011-09-23 01:02:54 +00:00
|
|
|
return;
|
2018-10-17 16:45:22 +00:00
|
|
|
if (MATCH("flags", get_index, &state->cur_event.flags))
|
2011-09-23 01:02:54 +00:00
|
|
|
return;
|
2018-10-17 16:45:22 +00:00
|
|
|
if (MATCH("value", get_index, &state->cur_event.value))
|
2011-10-01 04:55:51 +00:00
|
|
|
return;
|
2018-10-17 16:45:22 +00:00
|
|
|
if (MATCH("divemode", event_divemode, &state->cur_event.value))
|
2018-04-07 12:56:37 +00:00
|
|
|
return;
|
2018-10-17 16:45:22 +00:00
|
|
|
if (MATCH("cylinder", get_index, &state->cur_event.gas.index)) {
|
2014-08-17 18:26:21 +00:00
|
|
|
/* We add one to indicate that we got an actual cylinder index value */
|
2018-10-17 16:45:22 +00:00
|
|
|
state->cur_event.gas.index++;
|
2014-08-17 18:26:21 +00:00
|
|
|
return;
|
|
|
|
}
|
2018-10-17 16:45:22 +00:00
|
|
|
if (MATCH("o2", percent, &state->cur_event.gas.mix.o2))
|
2014-08-17 18:26:21 +00:00
|
|
|
return;
|
2018-10-17 16:45:22 +00:00
|
|
|
if (MATCH("he", percent, &state->cur_event.gas.mix.he))
|
2014-08-17 18:26:21 +00:00
|
|
|
return;
|
2011-09-23 01:02:54 +00:00
|
|
|
nonmatch("event", name, buf);
|
|
|
|
}
|
|
|
|
|
2018-10-17 16:45:22 +00:00
|
|
|
static int match_dc_data_fields(struct divecomputer *dc, const char *name, char *buf, struct parser_state *state)
|
2013-01-23 18:25:31 +00:00
|
|
|
{
|
2018-10-17 16:45:22 +00:00
|
|
|
if (MATCH_STATE("maxdepth", depth, &dc->maxdepth))
|
2013-01-23 18:25:31 +00:00
|
|
|
return 1;
|
2018-10-17 16:45:22 +00:00
|
|
|
if (MATCH_STATE("meandepth", depth, &dc->meandepth))
|
2013-01-23 18:25:31 +00:00
|
|
|
return 1;
|
2018-10-17 16:45:22 +00:00
|
|
|
if (MATCH_STATE("max.depth", depth, &dc->maxdepth))
|
2013-01-23 18:25:31 +00:00
|
|
|
return 1;
|
2018-10-17 16:45:22 +00:00
|
|
|
if (MATCH_STATE("mean.depth", depth, &dc->meandepth))
|
2013-01-23 18:25:31 +00:00
|
|
|
return 1;
|
2013-11-02 19:00:16 +00:00
|
|
|
if (MATCH("duration", duration, &dc->duration))
|
2013-01-23 18:25:31 +00:00
|
|
|
return 1;
|
2013-11-02 19:00:16 +00:00
|
|
|
if (MATCH("divetime", duration, &dc->duration))
|
2013-01-23 18:25:31 +00:00
|
|
|
return 1;
|
2013-11-02 19:00:16 +00:00
|
|
|
if (MATCH("divetimesec", duration, &dc->duration))
|
2013-01-23 18:25:31 +00:00
|
|
|
return 1;
|
Improve profile display in planner
This patch allows the planner to save the last manually-entered
dive planner point of a dive plan. When the plan has been saved
and re-opened for edit, the time of the last-entered dive planner
point is used to ensure that dive planning continues from the same
point in the profile as was when the original dive plan was saved.
Mechanism:
1) In dive.h, create a new dc attribute dc->last_manual_time
with data type of duration_t.
2) In diveplanner.c, ensure that the last manually-entered
dive planner point is saved in dc->last_manual_time.
3) In save-xml.c, create a new XML attribute for the <divecomputer>
element, named last-manual-time. For dive plans, the element would
now look like:
<divecomputer model='planned dive' last-manual-time='31:17 min'>
4) In parse-xml.c, insert code that recognises the last-manual-time
XML attribute, reads the time value and assigns this time to
dc->last_manual_time.
5) In diveplannermodel.cpp, method DiveplannerPointModel::loadfromdive,
insert code that sets the appropriate boolean value to dp->entered
by comparing newtime (i.e. time of dp) with dc->last_manual_time.
6) Diveplannermodel.cpp also accepts profile data from normal dives in
the dive log, whether hand-entered or loaded from dive computer. It
looks like the reduction of dive points for dives with >100 points
continues to work ok.
The result is that when a dive plan is saved with manually entered
points up to e.g. 10 minutes into the dive, it can be re-opened for edit
in the dive planner and the planner re-creates the plan with manually
entered points up to 10 minutes. The rest of the points are "soft"
points, shaped by the deco calculations of the planner.
Improvements: Improve code for profile display in dive planner
This responds to #1052.
Change load-git.c and save-git.c so that the last-manual-time is
also saved in the git-format dive log.
Several stylistic changes in text for consistent C source code.
Improvement of dive planner profile display:
Do some simplification of my alterations to diveplannermodel.cpp
Two small style changes in planner.c and diveplannermodel.cpp
as requested ny @neolit123
Signed-off-by: Willem Ferguson <willemferguson@zoology.up.ac.za>
2018-01-15 12:51:47 +00:00
|
|
|
if (MATCH("last-manual-time", duration, &dc->last_manual_time))
|
|
|
|
return 1;
|
2013-11-02 19:00:16 +00:00
|
|
|
if (MATCH("surfacetime", duration, &dc->surfacetime))
|
2013-01-23 18:25:31 +00:00
|
|
|
return 1;
|
2018-10-17 16:45:22 +00:00
|
|
|
if (MATCH_STATE("airtemp", temperature, &dc->airtemp))
|
2013-01-23 18:25:31 +00:00
|
|
|
return 1;
|
2018-10-17 16:45:22 +00:00
|
|
|
if (MATCH_STATE("watertemp", temperature, &dc->watertemp))
|
2013-01-23 18:25:31 +00:00
|
|
|
return 1;
|
2018-10-17 16:45:22 +00:00
|
|
|
if (MATCH_STATE("air.temperature", temperature, &dc->airtemp))
|
2013-01-23 18:25:31 +00:00
|
|
|
return 1;
|
2018-10-17 16:45:22 +00:00
|
|
|
if (MATCH_STATE("water.temperature", temperature, &dc->watertemp))
|
2013-01-23 18:25:31 +00:00
|
|
|
return 1;
|
2018-10-17 16:45:22 +00:00
|
|
|
if (MATCH_STATE("pressure.surface", pressure, &dc->surface_pressure))
|
2013-01-23 18:25:31 +00:00
|
|
|
return 1;
|
2013-11-02 19:00:16 +00:00
|
|
|
if (MATCH("salinity.water", salinity, &dc->salinity))
|
2013-01-23 18:25:31 +00:00
|
|
|
return 1;
|
2024-03-01 21:53:43 +00:00
|
|
|
if (MATCH("key.extradata", utf8_string_std, &state->cur_extra_data.key))
|
2014-11-06 18:34:19 +00:00
|
|
|
return 1;
|
2024-03-01 21:53:43 +00:00
|
|
|
if (MATCH("value.extradata", utf8_string_std, &state->cur_extra_data.value))
|
2014-11-06 18:34:19 +00:00
|
|
|
return 1;
|
2015-09-03 20:25:00 +00:00
|
|
|
if (MATCH("divemode", get_dc_type, &dc->divemode))
|
|
|
|
return 1;
|
|
|
|
if (MATCH("salinity", salinity, &dc->salinity))
|
|
|
|
return 1;
|
2018-10-17 16:45:22 +00:00
|
|
|
if (MATCH_STATE("atmospheric", pressure, &dc->surface_pressure))
|
2015-09-03 20:25:00 +00:00
|
|
|
return 1;
|
2013-01-23 18:25:31 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-11-25 02:50:21 +00:00
|
|
|
/* We're in the top-level dive xml. Try to convert whatever value to a dive value */
|
2018-10-17 16:45:22 +00:00
|
|
|
static void try_to_fill_dc(struct divecomputer *dc, const char *name, char *buf, struct parser_state *state)
|
2012-11-25 02:50:21 +00:00
|
|
|
{
|
2016-06-21 04:07:36 +00:00
|
|
|
unsigned int deviceid;
|
|
|
|
|
2012-11-25 02:50:21 +00:00
|
|
|
start_match("divecomputer", name, buf);
|
|
|
|
|
2018-10-17 16:45:22 +00:00
|
|
|
if (MATCH_STATE("date", divedate, &dc->when))
|
2012-11-25 02:50:21 +00:00
|
|
|
return;
|
2018-10-17 16:45:22 +00:00
|
|
|
if (MATCH_STATE("time", divetime, &dc->when))
|
2012-11-25 02:50:21 +00:00
|
|
|
return;
|
2024-02-29 06:56:27 +00:00
|
|
|
if (MATCH("model", utf8_string, (char **)&dc->model))
|
2012-11-25 19:44:27 +00:00
|
|
|
return;
|
Clean up divecomputer 'device' handling
We have this odd legacy notion of a divecomputer 'device', that was
originally just basically the libdivecomputer 'EVENT_DEVINFO' report
that was associated with each dive. So it had firmware version,
deviceid, and serial number.
It had also gotten extended to do 'nickname' handling, and it was all
confusing, ugly and bad. It was particularly bad because it wasn't
actually a 'per device' thing at all: due to the firmware field, a dive
computer that got a firmware update forced a new 'device'.
To make matters worse, the 'deviceid' was also almost random, because
we've calculated it a couple of different ways, and libdivecomputer
itself has changed how the legacy 32-bit 'serial number' is expressed.
Finally, because of all these issues, we didn't even try to make the
thing unique, so it really ended up being a random snapshot of the state
of the dive computer at the time of a dive, and sometimes we'd pick one,
and sometimes another, since they weren't really well-defined.
So get rid of all this confusion.
The new rules:
- the actual random dive computer state at the time of a dive is kept
in the dive data. So if you want to know the firmware version, it
should be in the 'extra data'
- the only serial number that matters is the string one in the extra
data, because that's the one that actually matches what the dive
computer reports, and isn't some random 32-bit integer with ambiguous
formatting.
- the 'device id' - the thing we match with (together with the model
name, eg "Suunto EON Steel") is purely a hash of the real serial
number.
The device ID that libdivecomputer reports in EVENT_DEVINFO is
ignored, as is the device ID we've saved in the XML or git files. If
we have a serial number, the device ID will be uniquely associated
with that serial number, and if we don't have one, the device ID will
be zero (for 'match anything').
So now 'deviceid' is literally just a shorthand for the serial number
string, and the two are joined at the hip.
- the 'device' managament is _only_ used to track devices that have
serial numbers _and_ nicknames. So no more different device
structures just because one had a nickname and the other didn't etc.
Without a serial number, the device is 'anonymous' and fundamentally
cannot be distinguished from other devices of the same model, so a
nickname is meaningless. And without a nickname, there is no point in
creating a device data structure, since all the data is in the dive
itself and the device structure wouldn't add any value..
These rules mean that we no longer have ambiguous 'device' structures,
and we can never have duplicates that can confuse us.
This does mean that you can't give a nickname to a device that cannot be
uniquely identified with a serial number, but those are happily fairly
rare (and mostly older ones). Dirk said he'd look at what it takes to
give more dive computers proper serial numbers, and I already did it for
the Garmin Descent family yesterday.
(Honesty in advertizing: right now you can't add a nickname to a dive
computer that doesn't already have one, because such a dive computer
will not have a device structure. But that's a UI issue, and I'll sort
that out separately)
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2021-08-16 22:50:11 +00:00
|
|
|
if (MATCH("deviceid", hex_value, &deviceid))
|
2012-11-25 02:50:21 +00:00
|
|
|
return;
|
2013-11-02 19:00:16 +00:00
|
|
|
if (MATCH("diveid", hex_value, &dc->diveid))
|
2012-11-25 02:50:21 +00:00
|
|
|
return;
|
2015-01-10 23:01:15 +00:00
|
|
|
if (MATCH("dctype", get_dc_type, &dc->divemode))
|
2014-06-11 17:48:48 +00:00
|
|
|
return;
|
2021-07-20 10:28:34 +00:00
|
|
|
if (MATCH("no_o2sensors", get_uint8, &dc->no_o2sensors))
|
2014-06-11 17:48:48 +00:00
|
|
|
return;
|
2018-10-17 16:45:22 +00:00
|
|
|
if (match_dc_data_fields(dc, name, buf, state))
|
2013-01-23 18:25:31 +00:00
|
|
|
return;
|
|
|
|
|
2012-11-25 02:50:21 +00:00
|
|
|
nonmatch("divecomputer", name, buf);
|
|
|
|
}
|
|
|
|
|
2011-08-30 22:22:48 +00:00
|
|
|
/* We're in samples - try to convert the random xml value to something useful */
|
2018-10-17 16:45:22 +00:00
|
|
|
static void try_to_fill_sample(struct sample *sample, const char *name, char *buf, struct parser_state *state)
|
2011-08-30 22:22:48 +00:00
|
|
|
{
|
2012-12-31 02:11:01 +00:00
|
|
|
int in_deco;
|
Add support for loading and saving multiple pressure samples
This does both the XML and the git save format, because the changes
really are the same, even if the actual format differs in some details.
See how the two "save_samples()" routines both do the same basic setup,
for example.
This is fairly straightforward, with the possible exception of the odd
sensor = sample->sensor[0];
default in the git pressure loading code.
That line just means that if we do *not* have an explicit cylinder index
for the pressure reading, we will always end up filling in the new
pressure as the first pressure (because the cylinder index will match the
first sensor slot).
So that makes the "add_sample_pressure()" case always do the same thing it
used to do for the legacy case: fill in the first slot. The actual sensor
index may later change, since the legacy format has a "sensor=X" key value
pair that sets the sensor, but it will also use the first sensor slot,
making it all do exactly what it used to do.
And on the other hand, if we're loading new-style data with cylinder
pressure and sensor index together, we just end up using the new semantics
for add_sample_pressure(), which tries to keep the same slot for the same
sensor, but does the right thing if we already have other pressure values.
The XML code has no such issues at all, since it can't share the cases
anyway, and we need to have different node names for the different sensor
values and cannot just have multiple "pressure" entries. Have I mentioned
how much I despise XML lately?
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-07-26 02:10:03 +00:00
|
|
|
pressure_t p;
|
2011-08-30 23:23:47 +00:00
|
|
|
|
2011-09-01 18:22:05 +00:00
|
|
|
start_match("sample", name, buf);
|
2018-10-17 16:45:22 +00:00
|
|
|
if (MATCH_STATE("pressure.sample", pressure, &sample->pressure[0]))
|
2011-08-30 23:23:47 +00:00
|
|
|
return;
|
2018-10-17 16:45:22 +00:00
|
|
|
if (MATCH_STATE("cylpress.sample", pressure, &sample->pressure[0]))
|
2011-08-30 23:23:47 +00:00
|
|
|
return;
|
2018-10-17 16:45:22 +00:00
|
|
|
if (MATCH_STATE("pdiluent.sample", pressure, &sample->pressure[0]))
|
2014-11-17 11:25:00 +00:00
|
|
|
return;
|
2018-10-17 16:45:22 +00:00
|
|
|
if (MATCH_STATE("o2pressure.sample", pressure, &sample->pressure[1]))
|
2014-08-30 15:46:47 +00:00
|
|
|
return;
|
Add support for loading and saving multiple pressure samples
This does both the XML and the git save format, because the changes
really are the same, even if the actual format differs in some details.
See how the two "save_samples()" routines both do the same basic setup,
for example.
This is fairly straightforward, with the possible exception of the odd
sensor = sample->sensor[0];
default in the git pressure loading code.
That line just means that if we do *not* have an explicit cylinder index
for the pressure reading, we will always end up filling in the new
pressure as the first pressure (because the cylinder index will match the
first sensor slot).
So that makes the "add_sample_pressure()" case always do the same thing it
used to do for the legacy case: fill in the first slot. The actual sensor
index may later change, since the legacy format has a "sensor=X" key value
pair that sets the sensor, but it will also use the first sensor slot,
making it all do exactly what it used to do.
And on the other hand, if we're loading new-style data with cylinder
pressure and sensor index together, we just end up using the new semantics
for add_sample_pressure(), which tries to keep the same slot for the same
sensor, but does the right thing if we already have other pressure values.
The XML code has no such issues at all, since it can't share the cases
anyway, and we need to have different node names for the different sensor
values and cannot just have multiple "pressure" entries. Have I mentioned
how much I despise XML lately?
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-07-26 02:10:03 +00:00
|
|
|
/* Christ, this is ugly */
|
2018-10-17 16:45:22 +00:00
|
|
|
if (MATCH_STATE("pressure0.sample", pressure, &p)) {
|
Add support for loading and saving multiple pressure samples
This does both the XML and the git save format, because the changes
really are the same, even if the actual format differs in some details.
See how the two "save_samples()" routines both do the same basic setup,
for example.
This is fairly straightforward, with the possible exception of the odd
sensor = sample->sensor[0];
default in the git pressure loading code.
That line just means that if we do *not* have an explicit cylinder index
for the pressure reading, we will always end up filling in the new
pressure as the first pressure (because the cylinder index will match the
first sensor slot).
So that makes the "add_sample_pressure()" case always do the same thing it
used to do for the legacy case: fill in the first slot. The actual sensor
index may later change, since the legacy format has a "sensor=X" key value
pair that sets the sensor, but it will also use the first sensor slot,
making it all do exactly what it used to do.
And on the other hand, if we're loading new-style data with cylinder
pressure and sensor index together, we just end up using the new semantics
for add_sample_pressure(), which tries to keep the same slot for the same
sensor, but does the right thing if we already have other pressure values.
The XML code has no such issues at all, since it can't share the cases
anyway, and we need to have different node names for the different sensor
values and cannot just have multiple "pressure" entries. Have I mentioned
how much I despise XML lately?
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-07-26 02:10:03 +00:00
|
|
|
add_sample_pressure(sample, 0, p.mbar);
|
|
|
|
return;
|
|
|
|
}
|
2018-10-17 16:45:22 +00:00
|
|
|
if (MATCH_STATE("pressure1.sample", pressure, &p)) {
|
Add support for loading and saving multiple pressure samples
This does both the XML and the git save format, because the changes
really are the same, even if the actual format differs in some details.
See how the two "save_samples()" routines both do the same basic setup,
for example.
This is fairly straightforward, with the possible exception of the odd
sensor = sample->sensor[0];
default in the git pressure loading code.
That line just means that if we do *not* have an explicit cylinder index
for the pressure reading, we will always end up filling in the new
pressure as the first pressure (because the cylinder index will match the
first sensor slot).
So that makes the "add_sample_pressure()" case always do the same thing it
used to do for the legacy case: fill in the first slot. The actual sensor
index may later change, since the legacy format has a "sensor=X" key value
pair that sets the sensor, but it will also use the first sensor slot,
making it all do exactly what it used to do.
And on the other hand, if we're loading new-style data with cylinder
pressure and sensor index together, we just end up using the new semantics
for add_sample_pressure(), which tries to keep the same slot for the same
sensor, but does the right thing if we already have other pressure values.
The XML code has no such issues at all, since it can't share the cases
anyway, and we need to have different node names for the different sensor
values and cannot just have multiple "pressure" entries. Have I mentioned
how much I despise XML lately?
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-07-26 02:10:03 +00:00
|
|
|
add_sample_pressure(sample, 1, p.mbar);
|
|
|
|
return;
|
|
|
|
}
|
2018-10-17 16:45:22 +00:00
|
|
|
if (MATCH_STATE("pressure2.sample", pressure, &p)) {
|
Add support for loading and saving multiple pressure samples
This does both the XML and the git save format, because the changes
really are the same, even if the actual format differs in some details.
See how the two "save_samples()" routines both do the same basic setup,
for example.
This is fairly straightforward, with the possible exception of the odd
sensor = sample->sensor[0];
default in the git pressure loading code.
That line just means that if we do *not* have an explicit cylinder index
for the pressure reading, we will always end up filling in the new
pressure as the first pressure (because the cylinder index will match the
first sensor slot).
So that makes the "add_sample_pressure()" case always do the same thing it
used to do for the legacy case: fill in the first slot. The actual sensor
index may later change, since the legacy format has a "sensor=X" key value
pair that sets the sensor, but it will also use the first sensor slot,
making it all do exactly what it used to do.
And on the other hand, if we're loading new-style data with cylinder
pressure and sensor index together, we just end up using the new semantics
for add_sample_pressure(), which tries to keep the same slot for the same
sensor, but does the right thing if we already have other pressure values.
The XML code has no such issues at all, since it can't share the cases
anyway, and we need to have different node names for the different sensor
values and cannot just have multiple "pressure" entries. Have I mentioned
how much I despise XML lately?
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-07-26 02:10:03 +00:00
|
|
|
add_sample_pressure(sample, 2, p.mbar);
|
|
|
|
return;
|
|
|
|
}
|
2018-10-17 16:45:22 +00:00
|
|
|
if (MATCH_STATE("pressure3.sample", pressure, &p)) {
|
Add support for loading and saving multiple pressure samples
This does both the XML and the git save format, because the changes
really are the same, even if the actual format differs in some details.
See how the two "save_samples()" routines both do the same basic setup,
for example.
This is fairly straightforward, with the possible exception of the odd
sensor = sample->sensor[0];
default in the git pressure loading code.
That line just means that if we do *not* have an explicit cylinder index
for the pressure reading, we will always end up filling in the new
pressure as the first pressure (because the cylinder index will match the
first sensor slot).
So that makes the "add_sample_pressure()" case always do the same thing it
used to do for the legacy case: fill in the first slot. The actual sensor
index may later change, since the legacy format has a "sensor=X" key value
pair that sets the sensor, but it will also use the first sensor slot,
making it all do exactly what it used to do.
And on the other hand, if we're loading new-style data with cylinder
pressure and sensor index together, we just end up using the new semantics
for add_sample_pressure(), which tries to keep the same slot for the same
sensor, but does the right thing if we already have other pressure values.
The XML code has no such issues at all, since it can't share the cases
anyway, and we need to have different node names for the different sensor
values and cannot just have multiple "pressure" entries. Have I mentioned
how much I despise XML lately?
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-07-26 02:10:03 +00:00
|
|
|
add_sample_pressure(sample, 3, p.mbar);
|
|
|
|
return;
|
|
|
|
}
|
2018-10-17 16:45:22 +00:00
|
|
|
if (MATCH_STATE("pressure4.sample", pressure, &p)) {
|
Add support for loading and saving multiple pressure samples
This does both the XML and the git save format, because the changes
really are the same, even if the actual format differs in some details.
See how the two "save_samples()" routines both do the same basic setup,
for example.
This is fairly straightforward, with the possible exception of the odd
sensor = sample->sensor[0];
default in the git pressure loading code.
That line just means that if we do *not* have an explicit cylinder index
for the pressure reading, we will always end up filling in the new
pressure as the first pressure (because the cylinder index will match the
first sensor slot).
So that makes the "add_sample_pressure()" case always do the same thing it
used to do for the legacy case: fill in the first slot. The actual sensor
index may later change, since the legacy format has a "sensor=X" key value
pair that sets the sensor, but it will also use the first sensor slot,
making it all do exactly what it used to do.
And on the other hand, if we're loading new-style data with cylinder
pressure and sensor index together, we just end up using the new semantics
for add_sample_pressure(), which tries to keep the same slot for the same
sensor, but does the right thing if we already have other pressure values.
The XML code has no such issues at all, since it can't share the cases
anyway, and we need to have different node names for the different sensor
values and cannot just have multiple "pressure" entries. Have I mentioned
how much I despise XML lately?
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-07-26 02:10:03 +00:00
|
|
|
add_sample_pressure(sample, 4, p.mbar);
|
|
|
|
return;
|
|
|
|
}
|
2018-10-17 16:45:22 +00:00
|
|
|
if (MATCH_STATE("cylinderindex.sample", get_cylinderindex, &sample->sensor[0]))
|
First step in cleaning up cylinder pressure sensor logic
This clarifies/changes the meaning of our "cylinderindex" entry in our
samples. It has been rather confused, because different dive computers
have done things differently, and the naming really hasn't helped.
There are two totally different - and independent - cylinder "indexes":
- the pressure sensor index, which indicates which cylinder the sensor
data is from.
- the "active cylinder" index, which indicates which cylinder we actually
breathe from.
These two values really are totally independent, and have nothing
what-so-ever to do with each other. The sensor index may well be fixed:
many dive computers only support a single pressure sensor (whether
wireless or wired), and the sensor index is thus always zero.
Other dive computers may support multiple pressure sensors, and the gas
switch event may - or may not - indicate that the sensor changed too. A
dive computer might give the sensor data for *all* cylinders it can read,
regardless of which one is the one we're actively breathing. In fact, some
dive computers might give sensor data for not just *your* cylinder, but
your buddies.
This patch renames "cylinderindex" in the samples as "sensor", making it
quite clear that it's about which sensor index the pressure data in the
sample is about.
The way we figure out which is the currently active gas is with an
explicit has change event. If a computer (like the Uemis Zurich) joins the
two concepts together, then a sensor change should also create a gas
switch event. This patch also changes the Uemis importer to do that.
Finally, it should be noted that the plot info works totally separately
from the sample data, and is about what we actually *display*, not about
the sample pressures etc. In the plot info, the "cylinderindex" does in
fact mean the currently active cylinder, and while it is initially set to
match the sensor information from the samples, we then walk the gas change
events and fix it up - and if the active cylinder differs from the sensor
cylinder, we clear the sensor data.
[Dirk Hohndel: this conflicted with some of my recent changes - I think
I merged things correctly...]
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-31 04:00:51 +00:00
|
|
|
return;
|
Start cleaning up sensor indexing for multiple sensors
This is a very timid start at making us actually use multiple sensors
without the magical special case for just CCR oxygen tracking.
It mainly does:
- turn the "sample->sensor" index into an array of two indexes, to
match the pressures themselves.
- get rid of dive->{oxygen_cylinder_index,diluent_cylinder_index},
since a CCR dive should now simply set the sample->sensor[] indices
correctly instead.
- in a couple of places, start actually looping over the sensors rather
than special-case the O2 case (although often the small "loops" are
just unrolled, since it's just two cases.
but in many cases we still end up only covering the zero sensor case,
because the CCR O2 sensor code coverage was fairly limited.
It's entirely possible (even likely) that this migth break some existing
case: it tries to be a fairly direct ("stupid") translation of the old
code, but unlike the preparatory patch this does actually does change
some semantics.
For example, right now the git loader code assumes that if the git save
data contains a o2pressure entry, it just hardcodes the O2 sensor index
to 1.
In fact, one issue is going to simply be that our file formats do not
have that multiple sensor format, but instead had very clearly encoded
things as being the CCR O2 pressure sensor.
But this is hopefully close to usable, and I will need feedback (and
maybe test cases) from people who have existing CCR dives with pressure
data.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-07-21 02:49:45 +00:00
|
|
|
if (MATCH("sensor.sample", get_sensor, &sample->sensor[0]))
|
2011-10-19 17:06:11 +00:00
|
|
|
return;
|
2018-10-17 16:45:22 +00:00
|
|
|
if (MATCH_STATE("depth.sample", depth, &sample->depth))
|
2011-08-30 23:23:47 +00:00
|
|
|
return;
|
2018-10-17 16:45:22 +00:00
|
|
|
if (MATCH_STATE("temp.sample", temperature, &sample->temperature))
|
2011-09-01 23:41:10 +00:00
|
|
|
return;
|
2018-10-17 16:45:22 +00:00
|
|
|
if (MATCH_STATE("temperature.sample", temperature, &sample->temperature))
|
2011-08-30 23:23:47 +00:00
|
|
|
return;
|
2013-11-02 19:00:16 +00:00
|
|
|
if (MATCH("sampletime.sample", sampletime, &sample->time))
|
2011-08-30 23:23:47 +00:00
|
|
|
return;
|
2013-11-02 19:00:16 +00:00
|
|
|
if (MATCH("time.sample", sampletime, &sample->time))
|
2011-08-30 23:23:47 +00:00
|
|
|
return;
|
2013-11-02 19:00:16 +00:00
|
|
|
if (MATCH("ndl.sample", sampletime, &sample->ndl))
|
2012-12-01 21:02:30 +00:00
|
|
|
return;
|
2014-07-09 20:13:36 +00:00
|
|
|
if (MATCH("tts.sample", sampletime, &sample->tts))
|
|
|
|
return;
|
2013-11-02 19:00:16 +00:00
|
|
|
if (MATCH("in_deco.sample", get_index, &in_deco)) {
|
2012-12-31 02:11:01 +00:00
|
|
|
sample->in_deco = (in_deco == 1);
|
|
|
|
return;
|
|
|
|
}
|
2013-11-02 19:00:16 +00:00
|
|
|
if (MATCH("stoptime.sample", sampletime, &sample->stoptime))
|
2012-12-01 21:02:30 +00:00
|
|
|
return;
|
2018-10-17 16:45:22 +00:00
|
|
|
if (MATCH_STATE("stopdepth.sample", depth, &sample->stopdepth))
|
2012-12-01 21:02:30 +00:00
|
|
|
return;
|
2017-11-10 09:24:32 +00:00
|
|
|
if (MATCH("cns.sample", get_uint16, &sample->cns))
|
2012-12-11 21:40:07 +00:00
|
|
|
return;
|
2015-07-22 15:20:39 +00:00
|
|
|
if (MATCH("rbt.sample", sampletime, &sample->rbt))
|
|
|
|
return;
|
2014-10-11 07:49:48 +00:00
|
|
|
if (MATCH("sensor1.sample", double_to_o2pressure, &sample->o2sensor[0])) // CCR O2 sensor data
|
|
|
|
return;
|
|
|
|
if (MATCH("sensor2.sample", double_to_o2pressure, &sample->o2sensor[1]))
|
|
|
|
return;
|
2024-01-20 23:35:44 +00:00
|
|
|
if (MATCH("sensor3.sample", double_to_o2pressure, &sample->o2sensor[2]))
|
|
|
|
return;
|
|
|
|
if (MATCH("sensor4.sample", double_to_o2pressure, &sample->o2sensor[3]))
|
|
|
|
return;
|
|
|
|
if (MATCH("sensor5.sample", double_to_o2pressure, &sample->o2sensor[4]))
|
|
|
|
return;
|
|
|
|
if (MATCH("sensor6.sample", double_to_o2pressure, &sample->o2sensor[5])) // up to 6 CCR sensors
|
2014-10-11 07:49:48 +00:00
|
|
|
return;
|
2015-02-14 05:07:22 +00:00
|
|
|
if (MATCH("po2.sample", double_to_o2pressure, &sample->setpoint))
|
2012-12-11 21:40:07 +00:00
|
|
|
return;
|
Make parse-xml callbacks be type-safe
.. and fix the type breakage brought in by commit eaf6d564874a ("CCR code:
Change to sample structure")
The XML parsing callbacks pass a "void *" around, because the helper
function that matches the XML node names ("match()") does so for all the
different dive/sample/dc member nodes that all have different types.
But that also hid the fact that it very much depended on the various types
being regular "int" etc, rather than the denser types that were introduced
so that the CCR data wouldn't expand memory use excessively. As a result,
XML loading would overwrite other members, and possibly even the
allocation, when it wrote an "int" value to something that only was a
8-bit allocation.
I left the "utf8_string()" without type checking - so it still uses
"void *_res" for the result type, with the cast happening inside the
function.
That's because the result destination ends up being a bit mixed-up wrt
"const char **" and just plain "char **". Note that the thing we modify
itself isn't const (it's not "char *const *"), but the pointer, but we
basically sometimes assign a "const char *", and sometimes a "char *".
I considered making two different versions of the callback, but it just
wasn't worth it. So "utf8_string()" users still aren't type-checked, and
you'd better give it a pointer to something that is some kind of "char *"
This patch doesn't really change the calling convention of the matching
function itself, but it makes the wrapper macro ("MATCH()") take a
properly type-checked function pointer instead (with a dummy call to do
type checking), and then casts the pointer to the "void *" type for the
actual real call.
The function pointer call is not really portable (although it works on
all sane architectures, particularly since the cast only changes one
argument from one type of pointer to another), and to make matters worse
uses the gcc statement-expression extension. But all the compilers we use
seem to support that gcc'ism, so in practice this gives us type-safety
with no downsides.
(If we ever want to use MSVC to compile subsurface, I suspect we'll have
to ifdef out the statement expression use and not type-check things. Or
perhaps re-write the thing as a ternary expression instead, or something).
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-06-07 21:41:07 +00:00
|
|
|
if (MATCH("heartbeat", get_uint8, &sample->heartbeat))
|
2014-01-17 22:00:28 +00:00
|
|
|
return;
|
Make parse-xml callbacks be type-safe
.. and fix the type breakage brought in by commit eaf6d564874a ("CCR code:
Change to sample structure")
The XML parsing callbacks pass a "void *" around, because the helper
function that matches the XML node names ("match()") does so for all the
different dive/sample/dc member nodes that all have different types.
But that also hid the fact that it very much depended on the various types
being regular "int" etc, rather than the denser types that were introduced
so that the CCR data wouldn't expand memory use excessively. As a result,
XML loading would overwrite other members, and possibly even the
allocation, when it wrote an "int" value to something that only was a
8-bit allocation.
I left the "utf8_string()" without type checking - so it still uses
"void *_res" for the result type, with the cast happening inside the
function.
That's because the result destination ends up being a bit mixed-up wrt
"const char **" and just plain "char **". Note that the thing we modify
itself isn't const (it's not "char *const *"), but the pointer, but we
basically sometimes assign a "const char *", and sometimes a "char *".
I considered making two different versions of the callback, but it just
wasn't worth it. So "utf8_string()" users still aren't type-checked, and
you'd better give it a pointer to something that is some kind of "char *"
This patch doesn't really change the calling convention of the matching
function itself, but it makes the wrapper macro ("MATCH()") take a
properly type-checked function pointer instead (with a dummy call to do
type checking), and then casts the pointer to the "void *" type for the
actual real call.
The function pointer call is not really portable (although it works on
all sane architectures, particularly since the cast only changes one
argument from one type of pointer to another), and to make matters worse
uses the gcc statement-expression extension. But all the compilers we use
seem to support that gcc'ism, so in practice this gives us type-safety
with no downsides.
(If we ever want to use MSVC to compile subsurface, I suspect we'll have
to ifdef out the statement expression use and not type-check things. Or
perhaps re-write the thing as a ternary expression instead, or something).
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-06-07 21:41:07 +00:00
|
|
|
if (MATCH("bearing", get_bearing, &sample->bearing))
|
2014-01-17 22:00:28 +00:00
|
|
|
return;
|
2015-09-03 20:25:00 +00:00
|
|
|
if (MATCH("setpoint.sample", double_to_o2pressure, &sample->setpoint))
|
|
|
|
return;
|
2018-10-17 16:45:22 +00:00
|
|
|
if (MATCH("ppo2.sample", double_to_o2pressure, &sample->o2sensor[state->next_o2_sensor])) {
|
|
|
|
state->next_o2_sensor++;
|
2015-09-03 20:25:00 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (MATCH("deco.sample", parse_libdc_deco, sample))
|
|
|
|
return;
|
|
|
|
if (MATCH("time.deco", sampletime, &sample->stoptime))
|
|
|
|
return;
|
2018-10-17 16:45:22 +00:00
|
|
|
if (MATCH_STATE("depth.deco", depth, &sample->stopdepth))
|
2015-09-03 20:25:00 +00:00
|
|
|
return;
|
2011-08-30 23:23:47 +00:00
|
|
|
|
2018-10-17 16:45:22 +00:00
|
|
|
switch (state->import_source) {
|
2024-02-29 06:56:27 +00:00
|
|
|
case parser_state::DIVINGLOG:
|
2018-10-17 16:45:22 +00:00
|
|
|
if (divinglog_fill_sample(sample, name, buf, state))
|
2011-09-05 21:29:08 +00:00
|
|
|
return;
|
|
|
|
break;
|
2024-02-29 06:56:27 +00:00
|
|
|
case parser_state::UDDF:
|
2018-10-17 16:45:22 +00:00
|
|
|
if (uddf_fill_sample(sample, name, buf, state))
|
2011-09-07 00:33:52 +00:00
|
|
|
return;
|
|
|
|
break;
|
|
|
|
|
2011-09-05 20:45:14 +00:00
|
|
|
default:
|
|
|
|
break;
|
2011-09-02 18:32:48 +00:00
|
|
|
}
|
|
|
|
|
2011-09-01 18:22:05 +00:00
|
|
|
nonmatch("sample", name, buf);
|
2011-08-30 22:22:48 +00:00
|
|
|
}
|
|
|
|
|
2024-02-28 21:01:51 +00:00
|
|
|
static void divinglog_place(const char *place, struct dive *d, struct parser_state *state)
|
2011-09-05 21:29:08 +00:00
|
|
|
{
|
2015-02-15 18:25:21 +00:00
|
|
|
char buffer[1024];
|
2019-03-05 21:58:47 +00:00
|
|
|
struct dive_site *ds;
|
2011-09-05 21:29:08 +00:00
|
|
|
|
2015-02-12 05:46:02 +00:00
|
|
|
snprintf(buffer, sizeof(buffer),
|
|
|
|
"%s%s%s%s%s",
|
|
|
|
place,
|
2024-02-29 06:56:27 +00:00
|
|
|
!state->city.empty() ? ", " : "",
|
|
|
|
!state->city.empty() ? state->city.c_str() : "",
|
|
|
|
!state->country.empty() ? ", " : "",
|
|
|
|
!state->country.empty() ? state->country.c_str() : "");
|
2022-11-12 07:57:56 +00:00
|
|
|
ds = get_dive_site_by_name(buffer, state->log->sites);
|
2019-03-05 21:58:47 +00:00
|
|
|
if (!ds)
|
2022-11-12 07:57:56 +00:00
|
|
|
ds = create_dive_site(buffer, state->log->sites);
|
2019-03-05 21:58:47 +00:00
|
|
|
add_dive_to_dive_site(d, ds);
|
2011-09-05 21:29:08 +00:00
|
|
|
|
2017-10-03 06:03:44 +00:00
|
|
|
// TODO: capture the country / city info in the taxonomy instead
|
2024-02-29 06:56:27 +00:00
|
|
|
state->city.clear();
|
|
|
|
state->country.clear();
|
2011-09-05 21:29:08 +00:00
|
|
|
}
|
|
|
|
|
2018-10-17 16:45:22 +00:00
|
|
|
static int divinglog_dive_match(struct dive *dive, const char *name, char *buf, struct parser_state *state)
|
2013-11-02 19:00:16 +00:00
|
|
|
{
|
2019-08-04 16:44:57 +00:00
|
|
|
/* For cylinder related fields, we might have to create a cylinder first. */
|
2020-01-07 03:00:20 +00:00
|
|
|
cylinder_t cyl = empty_cylinder;
|
2024-02-29 06:56:27 +00:00
|
|
|
if (MATCH("tanktype", utf8_string, (char **)&cyl.type.description)) {
|
2019-08-04 16:44:57 +00:00
|
|
|
cylinder_t *cyl0 = get_or_create_cylinder(dive, 0);
|
|
|
|
free((void *)cyl0->type.description);
|
|
|
|
cyl0->type.description = cyl.type.description;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
if (MATCH("tanksize", cylindersize, &cyl.type.size)) {
|
|
|
|
get_or_create_cylinder(dive, 0)->type.size = cyl.type.size;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
if (MATCH_STATE("presw", pressure, &cyl.type.workingpressure)) {
|
|
|
|
get_or_create_cylinder(dive, 0)->type.workingpressure = cyl.type.workingpressure;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
if (MATCH_STATE("press", pressure, &cyl.start)) {
|
|
|
|
get_or_create_cylinder(dive, 0)->start = cyl.start;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
if (MATCH_STATE("prese", pressure, &cyl.end)) {
|
|
|
|
get_or_create_cylinder(dive, 0)->end = cyl.end;
|
|
|
|
return 1;
|
|
|
|
}
|
2018-10-17 16:45:22 +00:00
|
|
|
return MATCH_STATE("divedate", divedate, &dive->when) ||
|
|
|
|
MATCH_STATE("entrytime", divetime, &dive->when) ||
|
2014-02-16 23:42:56 +00:00
|
|
|
MATCH("divetime", duration, &dive->dc.duration) ||
|
2018-10-17 16:45:22 +00:00
|
|
|
MATCH_STATE("depth", depth, &dive->dc.maxdepth) ||
|
|
|
|
MATCH_STATE("depthavg", depth, &dive->dc.meandepth) ||
|
2014-02-16 23:42:56 +00:00
|
|
|
MATCH("comments", utf8_string, &dive->notes) ||
|
|
|
|
MATCH("names.buddy", utf8_string, &dive->buddy) ||
|
2024-02-29 06:56:27 +00:00
|
|
|
MATCH("name.country", utf8_string_std, &state->country) ||
|
|
|
|
MATCH("name.city", utf8_string_std, &state->city) ||
|
2019-03-05 21:58:47 +00:00
|
|
|
MATCH_STATE("name.place", divinglog_place, dive) ||
|
2014-02-16 23:42:56 +00:00
|
|
|
0;
|
2011-09-05 21:29:08 +00:00
|
|
|
}
|
|
|
|
|
2011-09-07 00:33:52 +00:00
|
|
|
/*
|
|
|
|
* Uddf specifies ISO 8601 time format.
|
|
|
|
*
|
|
|
|
* There are many variations on that. This handles the useful cases.
|
|
|
|
*/
|
2024-02-28 21:01:51 +00:00
|
|
|
static void uddf_datetime(const char *buffer, timestamp_t *when, struct parser_state *state)
|
2011-09-07 00:33:52 +00:00
|
|
|
{
|
|
|
|
char c;
|
2014-02-16 23:42:56 +00:00
|
|
|
int y, m, d, hh, mm, ss;
|
2011-09-07 00:33:52 +00:00
|
|
|
struct tm tm = { 0 };
|
|
|
|
int i;
|
|
|
|
|
|
|
|
i = sscanf(buffer, "%d-%d-%d%c%d:%d:%d", &y, &m, &d, &c, &hh, &mm, &ss);
|
|
|
|
if (i == 7)
|
|
|
|
goto success;
|
|
|
|
ss = 0;
|
|
|
|
if (i == 6)
|
|
|
|
goto success;
|
|
|
|
|
|
|
|
i = sscanf(buffer, "%04d%02d%02d%c%02d%02d%02d", &y, &m, &d, &c, &hh, &mm, &ss);
|
|
|
|
if (i == 7)
|
|
|
|
goto success;
|
|
|
|
ss = 0;
|
|
|
|
if (i == 6)
|
|
|
|
goto success;
|
|
|
|
bad_date:
|
|
|
|
printf("Bad date time %s\n", buffer);
|
|
|
|
return;
|
|
|
|
|
|
|
|
success:
|
|
|
|
if (c != 'T' && c != ' ')
|
|
|
|
goto bad_date;
|
|
|
|
tm.tm_year = y;
|
|
|
|
tm.tm_mon = m - 1;
|
|
|
|
tm.tm_mday = d;
|
|
|
|
tm.tm_hour = hh;
|
|
|
|
tm.tm_min = mm;
|
|
|
|
tm.tm_sec = ss;
|
|
|
|
*when = utc_mktime(&tm);
|
|
|
|
}
|
|
|
|
|
2024-02-28 21:01:51 +00:00
|
|
|
#define uddf_datedata(name, offset) \
|
|
|
|
static void uddf_##name(const char *buffer, timestamp_t *when, struct parser_state *state) \
|
|
|
|
{ \
|
|
|
|
state->cur_tm.tm_##name = atoi(buffer) + offset; \
|
|
|
|
*when = utc_mktime(&state->cur_tm); \
|
2014-02-16 23:42:56 +00:00
|
|
|
}
|
2013-02-22 16:52:35 +00:00
|
|
|
|
|
|
|
uddf_datedata(year, 0)
|
|
|
|
uddf_datedata(mon, -1)
|
|
|
|
uddf_datedata(mday, 0)
|
|
|
|
uddf_datedata(hour, 0)
|
|
|
|
uddf_datedata(min, 0)
|
|
|
|
|
2018-10-17 16:45:22 +00:00
|
|
|
static int uddf_dive_match(struct dive *dive, const char *name, char *buf, struct parser_state *state)
|
2011-09-07 00:33:52 +00:00
|
|
|
{
|
2018-10-17 16:45:22 +00:00
|
|
|
return MATCH_STATE("datetime", uddf_datetime, &dive->when) ||
|
2014-02-16 23:42:56 +00:00
|
|
|
MATCH("diveduration", duration, &dive->dc.duration) ||
|
2018-10-17 16:45:22 +00:00
|
|
|
MATCH_STATE("greatestdepth", depth, &dive->dc.maxdepth) ||
|
|
|
|
MATCH_STATE("year.date", uddf_year, &dive->when) ||
|
|
|
|
MATCH_STATE("month.date", uddf_mon, &dive->when) ||
|
|
|
|
MATCH_STATE("day.date", uddf_mday, &dive->when) ||
|
|
|
|
MATCH_STATE("hour.time", uddf_hour, &dive->when) ||
|
|
|
|
MATCH_STATE("minute.time", uddf_min, &dive->when) ||
|
2014-02-16 23:42:56 +00:00
|
|
|
0;
|
2011-09-07 00:33:52 +00:00
|
|
|
}
|
|
|
|
|
2012-12-05 17:59:52 +00:00
|
|
|
/*
|
|
|
|
* This parses "floating point" into micro-degrees.
|
|
|
|
* We don't do exponentials etc, if somebody does
|
2015-09-04 23:03:14 +00:00
|
|
|
* GPS locations in that format, they are insane.
|
2012-12-05 17:59:52 +00:00
|
|
|
*/
|
2019-04-16 19:40:03 +00:00
|
|
|
static degrees_t parse_degrees(const char *buf, const char **end)
|
2012-12-05 17:59:52 +00:00
|
|
|
{
|
|
|
|
int sign = 1, decimals = 6, value = 0;
|
|
|
|
degrees_t ret;
|
|
|
|
|
2013-10-05 07:29:09 +00:00
|
|
|
while (isspace(*buf))
|
2012-12-05 17:59:52 +00:00
|
|
|
buf++;
|
|
|
|
switch (*buf) {
|
|
|
|
case '-':
|
|
|
|
sign = -1;
|
2014-02-16 23:42:56 +00:00
|
|
|
/* fallthrough */
|
2012-12-05 17:59:52 +00:00
|
|
|
case '+':
|
|
|
|
buf++;
|
|
|
|
}
|
|
|
|
while (isdigit(*buf)) {
|
2014-02-16 23:42:56 +00:00
|
|
|
value = 10 * value + *buf - '0';
|
2012-12-05 17:59:52 +00:00
|
|
|
buf++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get the first six decimals if they exist */
|
|
|
|
if (*buf == '.')
|
|
|
|
buf++;
|
|
|
|
do {
|
|
|
|
value *= 10;
|
|
|
|
if (isdigit(*buf)) {
|
|
|
|
value += *buf - '0';
|
|
|
|
buf++;
|
|
|
|
}
|
|
|
|
} while (--decimals);
|
|
|
|
|
|
|
|
/* Rounding */
|
|
|
|
switch (*buf) {
|
|
|
|
case '5' ... '9':
|
|
|
|
value++;
|
|
|
|
}
|
|
|
|
while (isdigit(*buf))
|
|
|
|
buf++;
|
|
|
|
|
|
|
|
*end = buf;
|
|
|
|
ret.udeg = value * sign;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2024-02-28 21:01:51 +00:00
|
|
|
static void gps_lat(const char *buffer, struct dive *dive, struct parser_state *state)
|
2013-01-23 19:53:42 +00:00
|
|
|
{
|
2019-04-16 19:40:03 +00:00
|
|
|
const char *end;
|
2018-10-20 18:12:15 +00:00
|
|
|
location_t location = { };
|
2015-02-13 05:26:43 +00:00
|
|
|
struct dive_site *ds = get_dive_site_for_dive(dive);
|
2018-10-20 18:12:15 +00:00
|
|
|
|
|
|
|
location.lat = parse_degrees(buffer, &end);
|
2015-02-13 05:26:43 +00:00
|
|
|
if (!ds) {
|
2022-11-12 07:57:56 +00:00
|
|
|
add_dive_to_dive_site(dive, create_dive_site_with_gps(NULL, &location, state->log->sites));
|
2015-02-13 05:26:43 +00:00
|
|
|
} else {
|
2018-10-20 18:12:15 +00:00
|
|
|
if (ds->location.lat.udeg && ds->location.lat.udeg != location.lat.udeg)
|
2015-02-13 05:26:43 +00:00
|
|
|
fprintf(stderr, "Oops, changing the latitude of existing dive site id %8x name %s; not good\n", ds->uuid, ds->name ?: "(unknown)");
|
2018-10-20 18:12:15 +00:00
|
|
|
ds->location.lat = location.lat;
|
2015-02-13 05:26:43 +00:00
|
|
|
}
|
2013-01-23 19:53:42 +00:00
|
|
|
}
|
|
|
|
|
2024-02-28 21:01:51 +00:00
|
|
|
static void gps_long(const char *buffer, struct dive *dive, struct parser_state *state)
|
2013-01-23 19:53:42 +00:00
|
|
|
{
|
2019-04-16 19:40:03 +00:00
|
|
|
const char *end;
|
2018-10-20 18:12:15 +00:00
|
|
|
location_t location = { };
|
2015-02-13 05:26:43 +00:00
|
|
|
struct dive_site *ds = get_dive_site_for_dive(dive);
|
2018-10-20 18:12:15 +00:00
|
|
|
|
|
|
|
location.lon = parse_degrees(buffer, &end);
|
2015-02-13 05:26:43 +00:00
|
|
|
if (!ds) {
|
2022-11-12 07:57:56 +00:00
|
|
|
add_dive_to_dive_site(dive, create_dive_site_with_gps(NULL, &location, state->log->sites));
|
2015-02-13 05:26:43 +00:00
|
|
|
} else {
|
2018-10-20 18:12:15 +00:00
|
|
|
if (ds->location.lon.udeg && ds->location.lon.udeg != location.lon.udeg)
|
2015-02-13 05:26:43 +00:00
|
|
|
fprintf(stderr, "Oops, changing the longitude of existing dive site id %8x name %s; not good\n", ds->uuid, ds->name ?: "(unknown)");
|
2018-10-20 18:12:15 +00:00
|
|
|
ds->location.lon = location.lon;
|
2015-02-13 05:26:43 +00:00
|
|
|
}
|
2013-01-23 19:53:42 +00:00
|
|
|
}
|
|
|
|
|
2018-10-20 18:12:15 +00:00
|
|
|
/* We allow either spaces or a comma between the decimal degrees */
|
2024-02-28 21:01:51 +00:00
|
|
|
extern "C" void parse_location(const char *buffer, location_t *loc)
|
2011-09-16 01:16:07 +00:00
|
|
|
{
|
2019-04-16 19:40:03 +00:00
|
|
|
const char *end;
|
2018-10-20 18:12:15 +00:00
|
|
|
loc->lat = parse_degrees(buffer, &end);
|
|
|
|
if (*end == ',') end++;
|
|
|
|
loc->lon = parse_degrees(end, &end);
|
|
|
|
}
|
2011-09-16 01:16:07 +00:00
|
|
|
|
2024-02-28 21:01:51 +00:00
|
|
|
static void gps_location(const char *buffer, struct dive_site *ds)
|
2018-10-20 18:12:15 +00:00
|
|
|
{
|
|
|
|
parse_location(buffer, &ds->location);
|
2015-02-12 05:46:02 +00:00
|
|
|
}
|
|
|
|
|
2024-02-28 21:01:51 +00:00
|
|
|
static void gps_in_dive(const char *buffer, struct dive *dive, struct parser_state *state)
|
2015-02-12 05:46:02 +00:00
|
|
|
{
|
2018-10-26 15:03:54 +00:00
|
|
|
struct dive_site *ds = dive->dive_site;
|
2018-10-20 18:12:15 +00:00
|
|
|
location_t location;
|
|
|
|
|
|
|
|
parse_location(buffer, &location);
|
2018-10-26 15:03:54 +00:00
|
|
|
if (!ds) {
|
2015-06-10 18:52:18 +00:00
|
|
|
// check if we have a dive site within 20 meters of that gps fix
|
2022-11-12 07:57:56 +00:00
|
|
|
ds = get_dive_site_by_gps_proximity(&location, 20, state->log->sites);
|
2015-06-10 18:52:18 +00:00
|
|
|
|
2015-02-13 08:04:14 +00:00
|
|
|
if (ds) {
|
2015-06-10 18:52:18 +00:00
|
|
|
// found a site nearby; in case it turns out this one had a different name let's
|
|
|
|
// remember the original coordinates so we can create the correct dive site later
|
2018-10-17 16:45:22 +00:00
|
|
|
state->cur_location = location;
|
2015-02-13 08:04:14 +00:00
|
|
|
} else {
|
2022-11-12 07:57:56 +00:00
|
|
|
ds = create_dive_site_with_gps("", &location, state->log->sites);
|
2015-02-13 08:04:14 +00:00
|
|
|
}
|
2019-03-05 21:58:47 +00:00
|
|
|
add_dive_to_dive_site(dive, ds);
|
2015-02-12 05:46:02 +00:00
|
|
|
} else {
|
|
|
|
if (dive_site_has_gps_location(ds) &&
|
2018-10-20 18:12:15 +00:00
|
|
|
has_location(&location) && !same_location(&ds->location, &location)) {
|
2015-02-12 05:46:02 +00:00
|
|
|
// Houston, we have a problem
|
|
|
|
fprintf(stderr, "dive site uuid in dive, but gps location (%10.6f/%10.6f) different from dive location (%10.6f/%10.6f)\n",
|
2018-10-20 18:12:15 +00:00
|
|
|
ds->location.lat.udeg / 1000000.0, ds->location.lon.udeg / 1000000.0,
|
|
|
|
location.lat.udeg / 1000000.0, location.lon.udeg / 1000000.0);
|
2024-02-29 12:53:17 +00:00
|
|
|
std::string coords = printGPSCoordsC(&location);
|
|
|
|
ds->notes = add_to_string(ds->notes, translate("gettextFromC", "multiple GPS locations for this dive site; also %s\n"), coords.c_str());
|
2015-02-12 05:46:02 +00:00
|
|
|
} else {
|
2018-10-20 18:12:15 +00:00
|
|
|
ds->location = location;
|
2015-02-12 05:46:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-02-28 21:01:51 +00:00
|
|
|
static void gps_picture_location(const char *buffer, struct picture *pic)
|
2014-06-09 00:42:15 +00:00
|
|
|
{
|
2018-10-20 18:12:15 +00:00
|
|
|
parse_location(buffer, &pic->location);
|
2014-06-09 00:42:15 +00:00
|
|
|
}
|
|
|
|
|
2011-08-30 22:22:48 +00:00
|
|
|
/* We're in the top-level dive xml. Try to convert whatever value to a dive value */
|
2018-10-17 16:45:22 +00:00
|
|
|
static void try_to_fill_dive(struct dive *dive, const char *name, char *buf, struct parser_state *state)
|
2011-08-30 22:22:48 +00:00
|
|
|
{
|
2019-08-04 20:13:49 +00:00
|
|
|
cylinder_t *cyl = dive->cylinders.nr > 0 ? get_cylinder(dive, dive->cylinders.nr - 1) : NULL;
|
2020-11-01 13:40:57 +00:00
|
|
|
weightsystem_t *ws = dive->weightsystems.nr > 0 ?
|
|
|
|
&dive->weightsystems.weightsystems[dive->weightsystems.nr - 1] : NULL;
|
2019-08-04 16:44:57 +00:00
|
|
|
pressure_t p;
|
2020-11-01 13:40:57 +00:00
|
|
|
weight_t w;
|
2011-09-01 18:22:05 +00:00
|
|
|
start_match("dive", name, buf);
|
2011-09-05 21:29:08 +00:00
|
|
|
|
2018-10-17 16:45:22 +00:00
|
|
|
switch (state->import_source) {
|
2024-02-29 06:56:27 +00:00
|
|
|
case parser_state::DIVINGLOG:
|
2018-10-17 16:45:22 +00:00
|
|
|
if (divinglog_dive_match(dive, name, buf, state))
|
2011-09-05 21:29:08 +00:00
|
|
|
return;
|
|
|
|
break;
|
|
|
|
|
2024-02-29 06:56:27 +00:00
|
|
|
case parser_state::UDDF:
|
2018-10-17 16:45:22 +00:00
|
|
|
if (uddf_dive_match(dive, name, buf, state))
|
2011-09-07 00:33:52 +00:00
|
|
|
return;
|
|
|
|
break;
|
|
|
|
|
2011-09-05 21:29:08 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2019-03-05 21:58:47 +00:00
|
|
|
if (MATCH_STATE("divesiteid", dive_site, dive))
|
2015-02-12 05:46:02 +00:00
|
|
|
return;
|
2013-11-02 19:00:16 +00:00
|
|
|
if (MATCH("number", get_index, &dive->number))
|
2011-09-11 18:36:33 +00:00
|
|
|
return;
|
Get rid of crazy empty tag_list element at the start
So this is totally unrelated to the git repository format, except for
the fact that I noticed it while writing the git saving code.
The subsurface divetag list handling is being stupid, and has a
initial dummy entry at the head of the list for no good reason.
I say "no good reason", because there *is* a reason for it: it allows
code to avoid the special case of empty list and adding entries to
before the first entry etc etc. But that reason is a really *bad*
reason, because it's valid only because people don't understand basic
list manipulation and pointers to pointers.
So get rid of the dummy element, and do things right instead - by
passing a *pointer* to the list, instead of the list. And then when
traversing the list and looking for a place to insert things, don't go
to the next entry - just update the "pointer to pointer" to point to
the address of the next entry. Each entry in a C linked list is no
different than the list itself, so you can use the pointer to the
pointer to the next entry as a pointer to the list.
This is a pet peeve of mine. The real beauty of pointers can never be
understood unless you understand the indirection they allow. People
who grew up with Pascal and were corrupted by that mindset are
mentally stunted. Niklaus Wirth has a lot to answer for!
But never fear. You too can overcome that mental limitation, it just
needs some brain exercise. Reading this patch may help. In particular,
contemplate the new "taglist_add_divetag()".
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-03-10 17:18:13 +00:00
|
|
|
if (MATCH("tags", divetags, &dive->tag_list))
|
2013-04-09 15:54:36 +00:00
|
|
|
return;
|
2018-11-18 10:15:32 +00:00
|
|
|
if (MATCH("tripflag", get_notrip, &dive->notrip))
|
2012-08-22 05:04:24 +00:00
|
|
|
return;
|
2018-10-17 16:45:22 +00:00
|
|
|
if (MATCH_STATE("date", divedate, &dive->when))
|
2011-08-30 22:22:48 +00:00
|
|
|
return;
|
2018-10-17 16:45:22 +00:00
|
|
|
if (MATCH_STATE("time", divetime, &dive->when))
|
2011-08-30 22:22:48 +00:00
|
|
|
return;
|
2018-10-17 16:45:22 +00:00
|
|
|
if (MATCH_STATE("datetime", divedatetime, &dive->when))
|
2011-08-30 23:59:03 +00:00
|
|
|
return;
|
2013-01-23 18:25:31 +00:00
|
|
|
/*
|
|
|
|
* Legacy format note: per-dive depths and duration get saved
|
|
|
|
* in the first dive computer entry
|
|
|
|
*/
|
2018-10-17 16:45:22 +00:00
|
|
|
if (match_dc_data_fields(&dive->dc, name, buf, state))
|
2012-11-12 19:57:49 +00:00
|
|
|
return;
|
2013-01-23 18:25:31 +00:00
|
|
|
|
2020-04-11 15:41:56 +00:00
|
|
|
if (MATCH("filename.picture", utf8_string, &state->cur_picture.filename))
|
2014-06-09 00:42:15 +00:00
|
|
|
return;
|
2020-04-11 15:41:56 +00:00
|
|
|
if (MATCH("offset.picture", offsettime, &state->cur_picture.offset))
|
2014-06-09 00:42:15 +00:00
|
|
|
return;
|
2020-04-11 15:41:56 +00:00
|
|
|
if (MATCH("gps.picture", gps_picture_location, &state->cur_picture))
|
2014-06-09 00:42:15 +00:00
|
|
|
return;
|
2024-03-01 22:32:17 +00:00
|
|
|
if (std::string hash; MATCH("hash.picture", utf8_string_std, &hash)) {
|
2018-06-10 14:39:47 +00:00
|
|
|
/* Legacy -> ignore. */
|
2015-02-26 13:39:42 +00:00
|
|
|
return;
|
2018-02-18 15:22:34 +00:00
|
|
|
}
|
2019-08-04 16:44:57 +00:00
|
|
|
if (MATCH_STATE("cylinderstartpressure", pressure, &p)) {
|
|
|
|
get_or_create_cylinder(dive, 0)->start = p;
|
2011-08-31 00:45:03 +00:00
|
|
|
return;
|
2019-08-04 16:44:57 +00:00
|
|
|
}
|
|
|
|
if (MATCH_STATE("cylinderendpressure", pressure, &p)) {
|
|
|
|
get_or_create_cylinder(dive, 0)->end = p;
|
2011-08-31 00:45:03 +00:00
|
|
|
return;
|
2019-08-04 16:44:57 +00:00
|
|
|
}
|
2018-10-17 16:45:22 +00:00
|
|
|
if (MATCH_STATE("gps", gps_in_dive, dive))
|
2011-09-16 01:16:07 +00:00
|
|
|
return;
|
2018-10-17 16:45:22 +00:00
|
|
|
if (MATCH_STATE("Place", gps_in_dive, dive))
|
2013-02-25 07:20:58 +00:00
|
|
|
return;
|
2019-02-28 21:45:17 +00:00
|
|
|
if (MATCH_STATE("latitude", gps_lat, dive))
|
2013-01-23 19:53:42 +00:00
|
|
|
return;
|
2019-02-28 21:45:17 +00:00
|
|
|
if (MATCH_STATE("sitelat", gps_lat, dive))
|
2013-01-29 05:11:01 +00:00
|
|
|
return;
|
2019-02-28 21:45:17 +00:00
|
|
|
if (MATCH_STATE("lat", gps_lat, dive))
|
2013-02-25 07:20:58 +00:00
|
|
|
return;
|
2019-02-28 21:45:17 +00:00
|
|
|
if (MATCH_STATE("longitude", gps_long, dive))
|
2013-01-23 19:53:42 +00:00
|
|
|
return;
|
2019-02-28 21:45:17 +00:00
|
|
|
if (MATCH_STATE("sitelon", gps_long, dive))
|
2013-01-29 05:11:01 +00:00
|
|
|
return;
|
2019-02-28 21:45:17 +00:00
|
|
|
if (MATCH_STATE("lon", gps_long, dive))
|
2013-02-25 07:20:58 +00:00
|
|
|
return;
|
2018-10-17 16:45:22 +00:00
|
|
|
if (MATCH_STATE("location", add_dive_site, dive))
|
2011-09-02 02:56:04 +00:00
|
|
|
return;
|
2018-10-17 16:45:22 +00:00
|
|
|
if (MATCH_STATE("name.dive", add_dive_site, dive))
|
2013-01-23 19:53:42 +00:00
|
|
|
return;
|
2013-11-02 19:00:16 +00:00
|
|
|
if (MATCH("suit", utf8_string, &dive->suit))
|
2012-08-14 23:07:25 +00:00
|
|
|
return;
|
2013-11-02 19:00:16 +00:00
|
|
|
if (MATCH("divesuit", utf8_string, &dive->suit))
|
2012-08-18 03:22:37 +00:00
|
|
|
return;
|
2013-11-02 19:00:16 +00:00
|
|
|
if (MATCH("notes", utf8_string, &dive->notes))
|
2011-09-02 02:56:04 +00:00
|
|
|
return;
|
2022-02-12 13:03:18 +00:00
|
|
|
// For historic reasons, we accept dive guide as well as dive master
|
|
|
|
if (MATCH("diveguide", utf8_string, &dive->diveguide))
|
|
|
|
return;
|
|
|
|
if (MATCH("divemaster", utf8_string, &dive->diveguide))
|
2011-09-13 21:58:06 +00:00
|
|
|
return;
|
2013-11-02 19:00:16 +00:00
|
|
|
if (MATCH("buddy", utf8_string, &dive->buddy))
|
2011-09-13 21:58:06 +00:00
|
|
|
return;
|
2019-11-19 17:16:45 +00:00
|
|
|
if (MATCH("watersalinity", salinity, &dive->user_salinity))
|
|
|
|
return;
|
2013-11-02 19:00:16 +00:00
|
|
|
if (MATCH("rating.dive", get_rating, &dive->rating))
|
2011-12-07 19:58:16 +00:00
|
|
|
return;
|
2013-11-02 19:00:16 +00:00
|
|
|
if (MATCH("visibility.dive", get_rating, &dive->visibility))
|
2012-10-28 22:49:02 +00:00
|
|
|
return;
|
2019-11-29 05:08:14 +00:00
|
|
|
if (MATCH("wavesize.dive", get_rating, &dive->wavesize))
|
|
|
|
return;
|
|
|
|
if (MATCH("current.dive", get_rating, &dive->current))
|
|
|
|
return;
|
|
|
|
if (MATCH("surge.dive", get_rating, &dive->surge))
|
|
|
|
return;
|
|
|
|
if (MATCH("chill.dive", get_rating, &dive->chill))
|
|
|
|
return;
|
2019-04-30 10:42:33 +00:00
|
|
|
if (MATCH_STATE("airpressure.dive", pressure, &dive->surface_pressure))
|
|
|
|
return;
|
2020-11-01 13:40:57 +00:00
|
|
|
if (ws) {
|
2024-02-29 06:56:27 +00:00
|
|
|
if (MATCH("description.weightsystem", utf8_string, (char **)&ws->description))
|
2020-11-01 13:40:57 +00:00
|
|
|
return;
|
|
|
|
if (MATCH_STATE("weight.weightsystem", weight, &ws->weight))
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (MATCH_STATE("weight", weight, &w)) {
|
|
|
|
weightsystem_t ws = empty_weightsystem;
|
|
|
|
ws.weight = w;
|
|
|
|
add_cloned_weightsystem(&dive->weightsystems, ws);
|
2019-06-26 15:21:03 +00:00
|
|
|
return;
|
2020-11-01 13:40:57 +00:00
|
|
|
}
|
2019-08-04 16:44:57 +00:00
|
|
|
if (cyl) {
|
|
|
|
if (MATCH("size.cylinder", cylindersize, &cyl->type.size))
|
2015-11-03 02:03:01 +00:00
|
|
|
return;
|
2019-08-04 16:44:57 +00:00
|
|
|
if (MATCH_STATE("workpressure.cylinder", pressure, &cyl->type.workingpressure))
|
2015-11-03 02:03:01 +00:00
|
|
|
return;
|
2024-02-29 06:56:27 +00:00
|
|
|
if (MATCH("description.cylinder", utf8_string, (char **)&cyl->type.description))
|
2015-11-03 02:03:01 +00:00
|
|
|
return;
|
2019-08-04 16:44:57 +00:00
|
|
|
if (MATCH_STATE("start.cylinder", pressure, &cyl->start))
|
2015-11-03 02:03:01 +00:00
|
|
|
return;
|
2019-08-04 16:44:57 +00:00
|
|
|
if (MATCH_STATE("end.cylinder", pressure, &cyl->end))
|
2015-11-03 02:03:01 +00:00
|
|
|
return;
|
2019-08-04 16:44:57 +00:00
|
|
|
if (MATCH_STATE("use.cylinder", cylinder_use, &cyl->cylinder_use))
|
2015-11-03 02:03:01 +00:00
|
|
|
return;
|
2019-08-04 16:44:57 +00:00
|
|
|
if (MATCH_STATE("depth.cylinder", depth, &cyl->depth))
|
2017-11-27 17:20:21 +00:00
|
|
|
return;
|
2019-08-04 16:44:57 +00:00
|
|
|
if (MATCH_STATE("o2", gasmix, &cyl->gasmix.o2))
|
2015-11-03 02:03:01 +00:00
|
|
|
return;
|
2019-08-04 16:44:57 +00:00
|
|
|
if (MATCH_STATE("o2percent", gasmix, &cyl->gasmix.o2))
|
2015-11-03 02:03:01 +00:00
|
|
|
return;
|
2019-08-04 16:44:57 +00:00
|
|
|
if (MATCH("n2", gasmix_nitrogen, &cyl->gasmix))
|
2015-11-03 02:03:01 +00:00
|
|
|
return;
|
2019-08-04 16:44:57 +00:00
|
|
|
if (MATCH_STATE("he", gasmix, &cyl->gasmix.he))
|
2015-11-03 02:03:01 +00:00
|
|
|
return;
|
|
|
|
}
|
2018-10-17 16:45:22 +00:00
|
|
|
if (MATCH_STATE("air.divetemperature", temperature, &dive->airtemp))
|
2013-02-14 17:44:18 +00:00
|
|
|
return;
|
2018-10-17 16:45:22 +00:00
|
|
|
if (MATCH_STATE("water.divetemperature", temperature, &dive->watertemp))
|
2014-06-03 23:01:48 +00:00
|
|
|
return;
|
2019-12-12 21:58:53 +00:00
|
|
|
if (MATCH("invalid", get_bool, &dive->invalid))
|
|
|
|
return;
|
Start parsing gas mixes
The suunto xml is just completely crazy. What's the helium percentage
companion to "o2pct"? Would it be "hepct"? No. It's "hepct_0".
Ok, so they didn't number the first o2pct, which could be seen as sane:
that's the only mix value that should always exist. And they clearly
started their indexing with 0. So with multiple mixes, you'd then
expect "o2pct_1" and "hepct_1", right?
Wrong! Because XML people are crazy, the second O2 mix percentage is
obviously "o2pct_2". So the O2 percentages are one-based, with an
implicit one. But the He percentages are zero-based with an explicit
zero. So the second mix is "o2pct_2" and "hepct_1".
I'd like to ask what drugs Suunto people are on, but hey, it's a Finnish
company. No need to ask. Vodka explains everything. LOTS AND LOTS OF
VODKA.
In comparison, the libdivecomputer output is nice and sane, and uses a
'gasmix' node. Of course, now we have so many different XML nesting
nodes to check that I just made it an array of different noces. That
also allows me to mark the suunto case, so that we only do the "check
for crazy alcoholic xml entries" when it's a suunto file.
The "type of file" thing is probably a good idea for deciding on default
units too. Some day.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-09-01 20:32:52 +00:00
|
|
|
|
2011-09-01 18:22:05 +00:00
|
|
|
nonmatch("dive", name, buf);
|
2011-08-30 22:22:48 +00:00
|
|
|
}
|
2011-08-30 20:48:05 +00:00
|
|
|
|
2012-08-22 05:04:24 +00:00
|
|
|
/* We're in the top-level trip xml. Try to convert whatever value to a trip value */
|
2020-06-15 21:13:29 +00:00
|
|
|
static void try_to_fill_trip(dive_trip_t *dive_trip, const char *name, char *buf, struct parser_state *state)
|
2012-08-22 05:04:24 +00:00
|
|
|
{
|
|
|
|
start_match("trip", name, buf);
|
|
|
|
|
2013-11-02 19:00:16 +00:00
|
|
|
if (MATCH("location", utf8_string, &dive_trip->location))
|
2012-08-22 05:04:24 +00:00
|
|
|
return;
|
2013-11-02 19:00:16 +00:00
|
|
|
if (MATCH("notes", utf8_string, &dive_trip->notes))
|
2012-08-22 05:04:24 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
nonmatch("trip", name, buf);
|
|
|
|
}
|
|
|
|
|
2015-02-12 05:46:02 +00:00
|
|
|
/* We're processing a divesite entry - try to fill the components */
|
2020-09-06 10:39:51 +00:00
|
|
|
static void try_to_fill_dive_site(struct parser_state *state, const char *name, char *buf)
|
2015-02-12 05:46:02 +00:00
|
|
|
{
|
2020-09-06 10:39:51 +00:00
|
|
|
struct dive_site *ds = state->cur_dive_site;
|
2024-02-29 06:56:27 +00:00
|
|
|
std::string taxonomy_value;
|
2015-02-12 05:46:02 +00:00
|
|
|
|
2020-09-06 10:39:51 +00:00
|
|
|
start_match("divesite", name, buf);
|
2015-02-12 05:46:02 +00:00
|
|
|
|
|
|
|
if (MATCH("uuid", hex_value, &ds->uuid))
|
|
|
|
return;
|
|
|
|
if (MATCH("name", utf8_string, &ds->name))
|
|
|
|
return;
|
|
|
|
if (MATCH("description", utf8_string, &ds->description))
|
|
|
|
return;
|
|
|
|
if (MATCH("notes", utf8_string, &ds->notes))
|
|
|
|
return;
|
|
|
|
if (MATCH("gps", gps_location, ds))
|
|
|
|
return;
|
2020-09-06 10:39:51 +00:00
|
|
|
if (MATCH("cat.geo", get_index, &state->taxonomy_category))
|
2015-07-01 19:30:33 +00:00
|
|
|
return;
|
2020-09-06 10:39:51 +00:00
|
|
|
if (MATCH("origin.geo", get_index, &state->taxonomy_origin))
|
2015-07-01 19:30:33 +00:00
|
|
|
return;
|
2024-02-29 06:56:27 +00:00
|
|
|
if (MATCH("value.geo", utf8_string_std, &taxonomy_value)) {
|
2020-09-06 10:39:51 +00:00
|
|
|
/* The code assumes that "value.geo" comes last, which is against
|
|
|
|
* the expectations of an XML file. Let's at least make sure that
|
|
|
|
* cat and origin have been set! */
|
|
|
|
if (state->taxonomy_category < 0 || state->taxonomy_origin < 0) {
|
|
|
|
report_error("Warning: taxonomy value without origin or category");
|
|
|
|
} else {
|
2024-02-28 21:01:51 +00:00
|
|
|
taxonomy_set_category(&ds->taxonomy, (taxonomy_category)state->taxonomy_category,
|
2024-02-29 06:56:27 +00:00
|
|
|
taxonomy_value.c_str(), (taxonomy_origin)state->taxonomy_origin);
|
2020-09-06 10:39:51 +00:00
|
|
|
}
|
|
|
|
state->taxonomy_category = state->taxonomy_origin = -1;
|
2015-07-01 19:30:33 +00:00
|
|
|
return;
|
|
|
|
}
|
2015-02-12 05:46:02 +00:00
|
|
|
|
|
|
|
nonmatch("divesite", name, buf);
|
|
|
|
}
|
|
|
|
|
2020-06-17 20:45:33 +00:00
|
|
|
static void try_to_fill_filter(struct filter_preset *filter, const char *name, char *buf)
|
|
|
|
{
|
|
|
|
start_match("filterpreset", name, buf);
|
|
|
|
|
2024-02-29 06:56:27 +00:00
|
|
|
std::string s;
|
|
|
|
if (MATCH("name", utf8_string_std, &s)) {
|
|
|
|
filter_preset_set_name(filter, s.c_str());
|
2020-06-17 20:45:33 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nonmatch("filterpreset", name, buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void try_to_fill_fulltext(const char *name, char *buf, struct parser_state *state)
|
|
|
|
{
|
|
|
|
start_match("fulltext", name, buf);
|
|
|
|
|
2024-02-29 06:56:27 +00:00
|
|
|
if (MATCH("mode", utf8_string_std, &state->fulltext_string_mode))
|
2020-06-17 20:45:33 +00:00
|
|
|
return;
|
2024-02-29 06:56:27 +00:00
|
|
|
if (MATCH("fulltext", utf8_string_std, &state->fulltext))
|
2020-06-17 20:45:33 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
nonmatch("fulltext", name, buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void try_to_fill_filter_constraint(const char *name, char *buf, struct parser_state *state)
|
|
|
|
{
|
|
|
|
start_match("fulltext", name, buf);
|
|
|
|
|
2024-02-29 06:56:27 +00:00
|
|
|
if (MATCH("type", utf8_string_std, &state->filter_constraint_type))
|
2020-06-17 20:45:33 +00:00
|
|
|
return;
|
2024-02-29 06:56:27 +00:00
|
|
|
if (MATCH("string_mode", utf8_string_std, &state->filter_constraint_string_mode))
|
2020-06-17 20:45:33 +00:00
|
|
|
return;
|
2024-02-29 06:56:27 +00:00
|
|
|
if (MATCH("range_mode", utf8_string_std, &state->filter_constraint_range_mode))
|
2020-06-17 20:45:33 +00:00
|
|
|
return;
|
|
|
|
if (MATCH("negate", get_bool, &state->filter_constraint_negate))
|
|
|
|
return;
|
2024-02-29 06:56:27 +00:00
|
|
|
if (MATCH("constraint", utf8_string_std, &state->filter_constraint))
|
2020-06-17 20:45:33 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
nonmatch("fulltext", name, buf);
|
|
|
|
}
|
|
|
|
|
2018-10-17 16:45:22 +00:00
|
|
|
static bool entry(const char *name, char *buf, struct parser_state *state)
|
2011-08-30 04:32:27 +00:00
|
|
|
{
|
2015-02-13 07:35:52 +00:00
|
|
|
if (!strncmp(name, "version.program", sizeof("version.program") - 1) ||
|
2015-02-25 09:05:37 +00:00
|
|
|
!strncmp(name, "version.divelog", sizeof("version.divelog") - 1)) {
|
2015-02-13 07:35:52 +00:00
|
|
|
last_xml_version = atoi(buf);
|
2015-06-20 13:45:12 +00:00
|
|
|
report_datafile_version(last_xml_version);
|
2015-02-25 09:05:37 +00:00
|
|
|
}
|
2018-10-17 16:45:22 +00:00
|
|
|
if (state->in_userid) {
|
2015-02-25 09:05:37 +00:00
|
|
|
return true;
|
2014-04-11 06:17:35 +00:00
|
|
|
}
|
2018-10-17 16:45:22 +00:00
|
|
|
if (state->in_settings) {
|
2021-10-30 23:31:29 +00:00
|
|
|
try_to_fill_fingerprint(name, buf, state);
|
2018-10-17 16:45:22 +00:00
|
|
|
try_to_fill_dc_settings(name, buf, state);
|
2022-11-12 08:14:00 +00:00
|
|
|
try_to_match_autogroup(name, buf, state);
|
2015-02-25 09:05:37 +00:00
|
|
|
return true;
|
2012-12-26 21:47:54 +00:00
|
|
|
}
|
2018-10-17 16:45:22 +00:00
|
|
|
if (state->cur_dive_site) {
|
2020-09-06 10:39:51 +00:00
|
|
|
try_to_fill_dive_site(state, name, buf);
|
2015-02-25 09:05:37 +00:00
|
|
|
return true;
|
2015-02-12 05:46:02 +00:00
|
|
|
}
|
2020-06-17 20:45:33 +00:00
|
|
|
if (state->in_filter_constraint) {
|
|
|
|
try_to_fill_filter_constraint(name, buf, state);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (state->in_fulltext) {
|
|
|
|
try_to_fill_fulltext(name, buf, state);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (state->cur_filter) {
|
2024-03-01 21:44:45 +00:00
|
|
|
try_to_fill_filter(state->cur_filter.get(), name, buf);
|
2020-06-17 20:45:33 +00:00
|
|
|
return true;
|
|
|
|
}
|
2024-02-29 06:56:27 +00:00
|
|
|
if (state->event_active) {
|
2018-10-17 16:45:22 +00:00
|
|
|
try_to_fill_event(name, buf, state);
|
2015-02-25 09:05:37 +00:00
|
|
|
return true;
|
2011-09-23 01:02:54 +00:00
|
|
|
}
|
2018-10-17 16:45:22 +00:00
|
|
|
if (state->cur_sample) {
|
|
|
|
try_to_fill_sample(state->cur_sample, name, buf, state);
|
2015-02-25 09:05:37 +00:00
|
|
|
return true;
|
2011-08-30 20:48:05 +00:00
|
|
|
}
|
2018-10-17 16:45:22 +00:00
|
|
|
if (state->cur_dc) {
|
|
|
|
try_to_fill_dc(state->cur_dc, name, buf, state);
|
2015-02-25 09:05:37 +00:00
|
|
|
return true;
|
2012-11-25 02:50:21 +00:00
|
|
|
}
|
2018-10-17 16:45:22 +00:00
|
|
|
if (state->cur_dive) {
|
|
|
|
try_to_fill_dive(state->cur_dive, name, buf, state);
|
2015-02-25 09:05:37 +00:00
|
|
|
return true;
|
2011-08-30 20:48:05 +00:00
|
|
|
}
|
2018-10-17 16:45:22 +00:00
|
|
|
if (state->cur_trip) {
|
2020-06-15 21:13:29 +00:00
|
|
|
try_to_fill_trip(state->cur_trip, name, buf, state);
|
2015-02-25 09:05:37 +00:00
|
|
|
return true;
|
New XML format for saving dives
This patch makes the trips nest, and it also fixes the fact that you never
saved the trip notes (you could edit it, but saving would throw it away).
I did *not* change the indentation of the dives, so the trip stuff shows
up the the beginning of the line, at the same level as the <dive> and
<dives> thing. I think it's fairly readable xml, though, and we haven't
really had proper "indentation shows nesting" anyway, since the top-level
"<dives>" thing also didn't indent stuff inside of it.
Anyway, the way I wrote it, it still parses your old "INTRIP" stuff etc,
so as far as I know, it should happily read the old-style XML too. At
least it seemed to work with your xml file that already had the old-style
one (I haven't committed my divetrips, exactly because I didn't like the
new format).
It always saves in the new style, though.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-09-30 19:36:18 +00:00
|
|
|
}
|
2015-02-25 09:05:37 +00:00
|
|
|
return true;
|
2011-08-30 04:32:27 +00:00
|
|
|
}
|
|
|
|
|
2011-08-30 00:51:54 +00:00
|
|
|
static const char *nodename(xmlNode *node, char *buf, int len)
|
2011-08-28 23:58:26 +00:00
|
|
|
{
|
2013-11-02 19:00:16 +00:00
|
|
|
int levels = 2;
|
|
|
|
char *p = buf;
|
|
|
|
|
2015-06-22 04:43:38 +00:00
|
|
|
if (!node || (node->type != XML_CDATA_SECTION_NODE && !node->name)) {
|
2011-08-30 21:38:39 +00:00
|
|
|
return "root";
|
2014-10-28 09:13:59 +00:00
|
|
|
}
|
2011-08-30 00:51:54 +00:00
|
|
|
|
2015-05-28 12:59:08 +00:00
|
|
|
if (node->type == XML_CDATA_SECTION_NODE || (node->parent && !strcmp((const char *)node->name, "text")))
|
2013-11-02 19:00:16 +00:00
|
|
|
node = node->parent;
|
|
|
|
|
|
|
|
/* Make sure it's always NUL-terminated */
|
|
|
|
p[--len] = 0;
|
2011-08-30 00:51:54 +00:00
|
|
|
|
2014-02-16 23:42:56 +00:00
|
|
|
for (;;) {
|
2015-05-28 12:59:08 +00:00
|
|
|
const char *name = (const char *)node->name;
|
2013-11-02 19:00:16 +00:00
|
|
|
char c;
|
|
|
|
while ((c = *name++) != 0) {
|
|
|
|
/* Cheaper 'tolower()' for ASCII */
|
|
|
|
c = (c >= 'A' && c <= 'Z') ? c - 'A' + 'a' : c;
|
|
|
|
*p++ = c;
|
2011-08-30 00:51:54 +00:00
|
|
|
if (!--len)
|
|
|
|
return buf;
|
|
|
|
}
|
2013-11-02 19:00:16 +00:00
|
|
|
*p = 0;
|
2011-08-30 00:51:54 +00:00
|
|
|
node = node->parent;
|
|
|
|
if (!node || !node->name)
|
|
|
|
return buf;
|
2013-11-02 19:00:16 +00:00
|
|
|
*p++ = '.';
|
2011-08-30 00:51:54 +00:00
|
|
|
if (!--len)
|
|
|
|
return buf;
|
2013-11-02 19:00:16 +00:00
|
|
|
if (!--levels)
|
|
|
|
return buf;
|
2011-08-30 00:51:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-02 19:00:16 +00:00
|
|
|
#define MAXNAME 32
|
2011-08-30 00:51:54 +00:00
|
|
|
|
2018-10-17 16:45:22 +00:00
|
|
|
static bool visit_one_node(xmlNode *node, struct parser_state *state)
|
2011-08-30 00:51:54 +00:00
|
|
|
{
|
2015-05-28 12:59:08 +00:00
|
|
|
xmlChar *content;
|
2018-09-21 11:23:36 +00:00
|
|
|
char buffer[MAXNAME];
|
2011-08-30 00:51:54 +00:00
|
|
|
const char *name;
|
|
|
|
|
|
|
|
content = node->content;
|
2012-12-28 16:18:23 +00:00
|
|
|
if (!content || xmlIsBlankNode(node))
|
2015-02-25 09:05:37 +00:00
|
|
|
return true;
|
2011-08-30 00:51:54 +00:00
|
|
|
|
|
|
|
name = nodename(node, buffer, sizeof(buffer));
|
2011-08-28 23:58:26 +00:00
|
|
|
|
2018-10-17 16:45:22 +00:00
|
|
|
return entry(name, (char *)content, state);
|
2011-08-28 23:58:26 +00:00
|
|
|
}
|
|
|
|
|
2018-10-17 16:45:22 +00:00
|
|
|
static bool traverse(xmlNode *root, struct parser_state *state);
|
2011-09-01 18:22:05 +00:00
|
|
|
|
2018-10-17 16:45:22 +00:00
|
|
|
static bool traverse_properties(xmlNode *node, struct parser_state *state)
|
2011-09-01 18:22:05 +00:00
|
|
|
{
|
|
|
|
xmlAttr *p;
|
2015-02-25 09:05:37 +00:00
|
|
|
bool ret = true;
|
2011-09-01 18:22:05 +00:00
|
|
|
|
|
|
|
for (p = node->properties; p; p = p->next)
|
2018-10-17 16:45:22 +00:00
|
|
|
if ((ret = traverse(p->children, state)) == false)
|
2015-02-25 09:05:37 +00:00
|
|
|
break;
|
|
|
|
return ret;
|
2011-09-01 18:22:05 +00:00
|
|
|
}
|
|
|
|
|
2018-10-17 16:45:22 +00:00
|
|
|
static bool visit(xmlNode *n, struct parser_state *state)
|
2011-09-01 18:22:05 +00:00
|
|
|
{
|
2018-10-17 16:45:22 +00:00
|
|
|
return visit_one_node(n, state) && traverse_properties(n, state) && traverse(n->children, state);
|
2011-09-01 18:22:05 +00:00
|
|
|
}
|
|
|
|
|
2018-10-17 16:45:22 +00:00
|
|
|
static void DivingLog_importer(struct parser_state *state)
|
2011-09-05 21:29:08 +00:00
|
|
|
{
|
2024-02-29 06:56:27 +00:00
|
|
|
state->import_source = parser_state::DIVINGLOG;
|
2011-09-05 21:29:08 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Diving Log units are really strange.
|
|
|
|
*
|
|
|
|
* Temperatures are in C, except in samples,
|
|
|
|
* when they are in Fahrenheit. Depths are in
|
2011-09-11 19:24:57 +00:00
|
|
|
* meters, an dpressure is in PSI in the samples,
|
|
|
|
* but in bar when it comes to working pressure.
|
|
|
|
*
|
|
|
|
* Crazy f*%^ morons.
|
2011-09-05 21:29:08 +00:00
|
|
|
*/
|
2018-10-17 16:45:22 +00:00
|
|
|
state->xml_parsing_units = SI_units;
|
2011-09-05 21:29:08 +00:00
|
|
|
}
|
|
|
|
|
2018-10-17 16:45:22 +00:00
|
|
|
static void uddf_importer(struct parser_state *state)
|
2011-09-07 00:01:28 +00:00
|
|
|
{
|
2024-02-29 06:56:27 +00:00
|
|
|
state->import_source = parser_state::UDDF;
|
2018-10-17 16:45:22 +00:00
|
|
|
state->xml_parsing_units = SI_units;
|
2024-02-28 21:01:51 +00:00
|
|
|
state->xml_parsing_units.pressure = units::PASCALS;
|
|
|
|
state->xml_parsing_units.temperature = units::KELVIN;
|
2011-09-07 00:01:28 +00:00
|
|
|
}
|
|
|
|
|
2019-08-04 16:59:14 +00:00
|
|
|
typedef void (*parser_func)(struct parser_state *);
|
Start parsing gas mixes
The suunto xml is just completely crazy. What's the helium percentage
companion to "o2pct"? Would it be "hepct"? No. It's "hepct_0".
Ok, so they didn't number the first o2pct, which could be seen as sane:
that's the only mix value that should always exist. And they clearly
started their indexing with 0. So with multiple mixes, you'd then
expect "o2pct_1" and "hepct_1", right?
Wrong! Because XML people are crazy, the second O2 mix percentage is
obviously "o2pct_2". So the O2 percentages are one-based, with an
implicit one. But the He percentages are zero-based with an explicit
zero. So the second mix is "o2pct_2" and "hepct_1".
I'd like to ask what drugs Suunto people are on, but hey, it's a Finnish
company. No need to ask. Vodka explains everything. LOTS AND LOTS OF
VODKA.
In comparison, the libdivecomputer output is nice and sane, and uses a
'gasmix' node. Of course, now we have so many different XML nesting
nodes to check that I just made it an array of different noces. That
also allows me to mark the suunto case, so that we only do the "check
for crazy alcoholic xml entries" when it's a suunto file.
The "type of file" thing is probably a good idea for deciding on default
units too. Some day.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-09-01 20:32:52 +00:00
|
|
|
/*
|
|
|
|
* I'm sure this could be done as some fancy DTD rules.
|
|
|
|
* It's just not worth the headache.
|
|
|
|
*/
|
|
|
|
static struct nesting {
|
|
|
|
const char *name;
|
2019-08-04 16:59:14 +00:00
|
|
|
parser_func start, end;
|
Start parsing gas mixes
The suunto xml is just completely crazy. What's the helium percentage
companion to "o2pct"? Would it be "hepct"? No. It's "hepct_0".
Ok, so they didn't number the first o2pct, which could be seen as sane:
that's the only mix value that should always exist. And they clearly
started their indexing with 0. So with multiple mixes, you'd then
expect "o2pct_1" and "hepct_1", right?
Wrong! Because XML people are crazy, the second O2 mix percentage is
obviously "o2pct_2". So the O2 percentages are one-based, with an
implicit one. But the He percentages are zero-based with an explicit
zero. So the second mix is "o2pct_2" and "hepct_1".
I'd like to ask what drugs Suunto people are on, but hey, it's a Finnish
company. No need to ask. Vodka explains everything. LOTS AND LOTS OF
VODKA.
In comparison, the libdivecomputer output is nice and sane, and uses a
'gasmix' node. Of course, now we have so many different XML nesting
nodes to check that I just made it an array of different noces. That
also allows me to mark the suunto case, so that we only do the "check
for crazy alcoholic xml entries" when it's a suunto file.
The "type of file" thing is probably a good idea for deciding on default
units too. Some day.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-09-01 20:32:52 +00:00
|
|
|
} nesting[] = {
|
2021-10-30 23:31:29 +00:00
|
|
|
{ "fingerprint", fingerprint_settings_start, fingerprint_settings_end },
|
2014-02-16 23:42:56 +00:00
|
|
|
{ "divecomputerid", dc_settings_start, dc_settings_end },
|
|
|
|
{ "settings", settings_start, settings_end },
|
2015-02-12 05:46:02 +00:00
|
|
|
{ "site", dive_site_start, dive_site_end },
|
2020-06-17 20:45:33 +00:00
|
|
|
{ "filterpreset", filter_preset_start, filter_preset_end },
|
|
|
|
{ "fulltext", fulltext_start, fulltext_end },
|
|
|
|
{ "constraint", filter_constraint_start, filter_constraint_end },
|
2014-02-16 23:42:56 +00:00
|
|
|
{ "dive", dive_start, dive_end },
|
|
|
|
{ "Dive", dive_start, dive_end },
|
|
|
|
{ "trip", trip_start, trip_end },
|
|
|
|
{ "sample", sample_start, sample_end },
|
|
|
|
{ "waypoint", sample_start, sample_end },
|
|
|
|
{ "SAMPLE", sample_start, sample_end },
|
|
|
|
{ "reading", sample_start, sample_end },
|
|
|
|
{ "event", event_start, event_end },
|
2019-08-04 16:59:14 +00:00
|
|
|
{ "mix", (parser_func)cylinder_start, (parser_func)cylinder_end },
|
|
|
|
{ "gasmix", (parser_func)cylinder_start, (parser_func)cylinder_end },
|
|
|
|
{ "cylinder", (parser_func)cylinder_start, (parser_func)cylinder_end },
|
2014-02-16 23:42:56 +00:00
|
|
|
{ "weightsystem", ws_start, ws_end },
|
|
|
|
{ "divecomputer", divecomputer_start, divecomputer_end },
|
|
|
|
{ "P", sample_start, sample_end },
|
2014-04-11 06:17:35 +00:00
|
|
|
{ "userid", userid_start, userid_stop},
|
2014-06-09 00:42:15 +00:00
|
|
|
{ "picture", picture_start, picture_end },
|
2014-11-06 18:34:19 +00:00
|
|
|
{ "extradata", extra_data_start, extra_data_end },
|
2014-02-16 23:42:56 +00:00
|
|
|
|
|
|
|
/* Import type recognition */
|
|
|
|
{ "Divinglog", DivingLog_importer },
|
|
|
|
{ "uddf", uddf_importer },
|
|
|
|
{ NULL, }
|
2018-10-17 16:45:22 +00:00
|
|
|
};
|
Start parsing gas mixes
The suunto xml is just completely crazy. What's the helium percentage
companion to "o2pct"? Would it be "hepct"? No. It's "hepct_0".
Ok, so they didn't number the first o2pct, which could be seen as sane:
that's the only mix value that should always exist. And they clearly
started their indexing with 0. So with multiple mixes, you'd then
expect "o2pct_1" and "hepct_1", right?
Wrong! Because XML people are crazy, the second O2 mix percentage is
obviously "o2pct_2". So the O2 percentages are one-based, with an
implicit one. But the He percentages are zero-based with an explicit
zero. So the second mix is "o2pct_2" and "hepct_1".
I'd like to ask what drugs Suunto people are on, but hey, it's a Finnish
company. No need to ask. Vodka explains everything. LOTS AND LOTS OF
VODKA.
In comparison, the libdivecomputer output is nice and sane, and uses a
'gasmix' node. Of course, now we have so many different XML nesting
nodes to check that I just made it an array of different noces. That
also allows me to mark the suunto case, so that we only do the "check
for crazy alcoholic xml entries" when it's a suunto file.
The "type of file" thing is probably a good idea for deciding on default
units too. Some day.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-09-01 20:32:52 +00:00
|
|
|
|
2018-10-17 16:45:22 +00:00
|
|
|
static bool traverse(xmlNode *root, struct parser_state *state)
|
2011-08-28 23:58:26 +00:00
|
|
|
{
|
|
|
|
xmlNode *n;
|
2015-02-25 09:05:37 +00:00
|
|
|
bool ret = true;
|
2011-08-28 23:58:26 +00:00
|
|
|
|
2011-09-01 18:22:05 +00:00
|
|
|
for (n = root; n; n = n->next) {
|
Start parsing gas mixes
The suunto xml is just completely crazy. What's the helium percentage
companion to "o2pct"? Would it be "hepct"? No. It's "hepct_0".
Ok, so they didn't number the first o2pct, which could be seen as sane:
that's the only mix value that should always exist. And they clearly
started their indexing with 0. So with multiple mixes, you'd then
expect "o2pct_1" and "hepct_1", right?
Wrong! Because XML people are crazy, the second O2 mix percentage is
obviously "o2pct_2". So the O2 percentages are one-based, with an
implicit one. But the He percentages are zero-based with an explicit
zero. So the second mix is "o2pct_2" and "hepct_1".
I'd like to ask what drugs Suunto people are on, but hey, it's a Finnish
company. No need to ask. Vodka explains everything. LOTS AND LOTS OF
VODKA.
In comparison, the libdivecomputer output is nice and sane, and uses a
'gasmix' node. Of course, now we have so many different XML nesting
nodes to check that I just made it an array of different noces. That
also allows me to mark the suunto case, so that we only do the "check
for crazy alcoholic xml entries" when it's a suunto file.
The "type of file" thing is probably a good idea for deciding on default
units too. Some day.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-09-01 20:32:52 +00:00
|
|
|
struct nesting *rule = nesting;
|
2011-08-30 04:32:27 +00:00
|
|
|
|
parse-xml: allow XML nodes with empty tag names
They happen for CDATA content, where libxml2 turns the CDATA fields into
a child of the parent entry, but without a name.
Now, of course, any sane person would just want to use the CDATA as the
string value of the parent itself, but libxml2 probably does this
insanity for a reason. And the reason is probably that some misguided
people want to *write* XML using libxml2, and then the stupid child node
actually acts as a "now I want you to write this data as CDATA".
Whatever the reason, let's just ignore it. We will just traverse such a
nameless child and be happy, and we'll give the nameless child the name
of the parent. Our XML node matching logic will then never see this
insane nameless child at all, and doesn't have to care.
Our whole XML parsing rule-of-thumb is to take the whole "be strict in
what you output, but generous in what you accept" to its logical
conclusion. Because we will literally accept almost anything, in any
format. You can mix tags or attributes wildly, and youc an use CDATA or
not as you see fit. We just don't care.
We're the honeybadger of the divelog world.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-29 05:12:32 +00:00
|
|
|
if (!n->name) {
|
2018-10-17 16:45:22 +00:00
|
|
|
if ((ret = visit(n, state)) == false)
|
2015-02-25 09:05:37 +00:00
|
|
|
break;
|
parse-xml: allow XML nodes with empty tag names
They happen for CDATA content, where libxml2 turns the CDATA fields into
a child of the parent entry, but without a name.
Now, of course, any sane person would just want to use the CDATA as the
string value of the parent itself, but libxml2 probably does this
insanity for a reason. And the reason is probably that some misguided
people want to *write* XML using libxml2, and then the stupid child node
actually acts as a "now I want you to write this data as CDATA".
Whatever the reason, let's just ignore it. We will just traverse such a
nameless child and be happy, and we'll give the nameless child the name
of the parent. Our XML node matching logic will then never see this
insane nameless child at all, and doesn't have to care.
Our whole XML parsing rule-of-thumb is to take the whole "be strict in
what you output, but generous in what you accept" to its logical
conclusion. Because we will literally accept almost anything, in any
format. You can mix tags or attributes wildly, and youc an use CDATA or
not as you see fit. We just don't care.
We're the honeybadger of the divelog world.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-29 05:12:32 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
Start parsing gas mixes
The suunto xml is just completely crazy. What's the helium percentage
companion to "o2pct"? Would it be "hepct"? No. It's "hepct_0".
Ok, so they didn't number the first o2pct, which could be seen as sane:
that's the only mix value that should always exist. And they clearly
started their indexing with 0. So with multiple mixes, you'd then
expect "o2pct_1" and "hepct_1", right?
Wrong! Because XML people are crazy, the second O2 mix percentage is
obviously "o2pct_2". So the O2 percentages are one-based, with an
implicit one. But the He percentages are zero-based with an explicit
zero. So the second mix is "o2pct_2" and "hepct_1".
I'd like to ask what drugs Suunto people are on, but hey, it's a Finnish
company. No need to ask. Vodka explains everything. LOTS AND LOTS OF
VODKA.
In comparison, the libdivecomputer output is nice and sane, and uses a
'gasmix' node. Of course, now we have so many different XML nesting
nodes to check that I just made it an array of different noces. That
also allows me to mark the suunto case, so that we only do the "check
for crazy alcoholic xml entries" when it's a suunto file.
The "type of file" thing is probably a good idea for deciding on default
units too. Some day.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-09-01 20:32:52 +00:00
|
|
|
do {
|
2015-05-28 12:59:08 +00:00
|
|
|
if (!strcmp(rule->name, (const char *)n->name))
|
Start parsing gas mixes
The suunto xml is just completely crazy. What's the helium percentage
companion to "o2pct"? Would it be "hepct"? No. It's "hepct_0".
Ok, so they didn't number the first o2pct, which could be seen as sane:
that's the only mix value that should always exist. And they clearly
started their indexing with 0. So with multiple mixes, you'd then
expect "o2pct_1" and "hepct_1", right?
Wrong! Because XML people are crazy, the second O2 mix percentage is
obviously "o2pct_2". So the O2 percentages are one-based, with an
implicit one. But the He percentages are zero-based with an explicit
zero. So the second mix is "o2pct_2" and "hepct_1".
I'd like to ask what drugs Suunto people are on, but hey, it's a Finnish
company. No need to ask. Vodka explains everything. LOTS AND LOTS OF
VODKA.
In comparison, the libdivecomputer output is nice and sane, and uses a
'gasmix' node. Of course, now we have so many different XML nesting
nodes to check that I just made it an array of different noces. That
also allows me to mark the suunto case, so that we only do the "check
for crazy alcoholic xml entries" when it's a suunto file.
The "type of file" thing is probably a good idea for deciding on default
units too. Some day.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-09-01 20:32:52 +00:00
|
|
|
break;
|
|
|
|
rule++;
|
|
|
|
} while (rule->name);
|
2011-08-30 04:32:27 +00:00
|
|
|
|
Start parsing gas mixes
The suunto xml is just completely crazy. What's the helium percentage
companion to "o2pct"? Would it be "hepct"? No. It's "hepct_0".
Ok, so they didn't number the first o2pct, which could be seen as sane:
that's the only mix value that should always exist. And they clearly
started their indexing with 0. So with multiple mixes, you'd then
expect "o2pct_1" and "hepct_1", right?
Wrong! Because XML people are crazy, the second O2 mix percentage is
obviously "o2pct_2". So the O2 percentages are one-based, with an
implicit one. But the He percentages are zero-based with an explicit
zero. So the second mix is "o2pct_2" and "hepct_1".
I'd like to ask what drugs Suunto people are on, but hey, it's a Finnish
company. No need to ask. Vodka explains everything. LOTS AND LOTS OF
VODKA.
In comparison, the libdivecomputer output is nice and sane, and uses a
'gasmix' node. Of course, now we have so many different XML nesting
nodes to check that I just made it an array of different noces. That
also allows me to mark the suunto case, so that we only do the "check
for crazy alcoholic xml entries" when it's a suunto file.
The "type of file" thing is probably a good idea for deciding on default
units too. Some day.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-09-01 20:32:52 +00:00
|
|
|
if (rule->start)
|
2018-10-17 16:45:22 +00:00
|
|
|
rule->start(state);
|
|
|
|
if ((ret = visit(n, state)) == false)
|
2015-02-25 09:05:37 +00:00
|
|
|
break;
|
Start parsing gas mixes
The suunto xml is just completely crazy. What's the helium percentage
companion to "o2pct"? Would it be "hepct"? No. It's "hepct_0".
Ok, so they didn't number the first o2pct, which could be seen as sane:
that's the only mix value that should always exist. And they clearly
started their indexing with 0. So with multiple mixes, you'd then
expect "o2pct_1" and "hepct_1", right?
Wrong! Because XML people are crazy, the second O2 mix percentage is
obviously "o2pct_2". So the O2 percentages are one-based, with an
implicit one. But the He percentages are zero-based with an explicit
zero. So the second mix is "o2pct_2" and "hepct_1".
I'd like to ask what drugs Suunto people are on, but hey, it's a Finnish
company. No need to ask. Vodka explains everything. LOTS AND LOTS OF
VODKA.
In comparison, the libdivecomputer output is nice and sane, and uses a
'gasmix' node. Of course, now we have so many different XML nesting
nodes to check that I just made it an array of different noces. That
also allows me to mark the suunto case, so that we only do the "check
for crazy alcoholic xml entries" when it's a suunto file.
The "type of file" thing is probably a good idea for deciding on default
units too. Some day.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2011-09-01 20:32:52 +00:00
|
|
|
if (rule->end)
|
2018-10-17 16:45:22 +00:00
|
|
|
rule->end(state);
|
2011-08-28 23:58:26 +00:00
|
|
|
}
|
2015-02-25 09:05:37 +00:00
|
|
|
return ret;
|
2011-08-28 23:58:26 +00:00
|
|
|
}
|
|
|
|
|
2011-09-02 18:32:48 +00:00
|
|
|
/* Per-file reset */
|
2018-10-17 16:45:22 +00:00
|
|
|
static void reset_all(struct parser_state *state)
|
2011-09-02 18:32:48 +00:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
* We reset the units for each file. You'd think it was
|
|
|
|
* a per-dive property, but I'm not going to trust people
|
|
|
|
* to do per-dive setup. If the xml does have per-dive
|
|
|
|
* data within one file, we might have to reset it per
|
|
|
|
* dive for that format.
|
|
|
|
*/
|
2018-10-17 16:45:22 +00:00
|
|
|
state->xml_parsing_units = SI_units;
|
2024-02-29 06:56:27 +00:00
|
|
|
state->import_source = parser_state::UNKNOWN;
|
2011-09-02 18:32:48 +00:00
|
|
|
}
|
|
|
|
|
2013-03-15 17:02:14 +00:00
|
|
|
/* divelog.de sends us xml files that claim to be iso-8859-1
|
|
|
|
* but once we decode the HTML encoded characters they turn
|
|
|
|
* into UTF-8 instead. So skip the incorrect encoding
|
|
|
|
* declaration and decode the HTML encoded characters */
|
2018-01-07 17:53:40 +00:00
|
|
|
static const char *preprocess_divelog_de(const char *buffer)
|
2013-03-15 17:02:14 +00:00
|
|
|
{
|
2024-02-28 21:01:51 +00:00
|
|
|
const char *ret = strstr(buffer, "<DIVELOGSDATA>");
|
2013-03-15 17:02:14 +00:00
|
|
|
|
|
|
|
if (ret) {
|
|
|
|
xmlParserCtxtPtr ctx;
|
|
|
|
char buf[] = "";
|
2016-03-10 02:26:59 +00:00
|
|
|
size_t i;
|
2013-03-26 19:59:22 +00:00
|
|
|
|
|
|
|
for (i = 0; i < strlen(ret); ++i)
|
|
|
|
if (!isascii(ret[i]))
|
|
|
|
return buffer;
|
2013-03-15 17:02:14 +00:00
|
|
|
|
|
|
|
ctx = xmlCreateMemoryParserCtxt(buf, sizeof(buf));
|
2015-05-28 12:59:08 +00:00
|
|
|
ret = (char *)xmlStringLenDecodeEntities(ctx, (xmlChar *)ret, strlen(ret), XML_SUBSTITUTE_REF, 0, 0, 0);
|
2013-03-15 17:02:14 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
return buffer;
|
|
|
|
}
|
|
|
|
|
2024-02-28 21:01:51 +00:00
|
|
|
extern "C" int parse_xml_buffer(const char *url, const char *buffer, int, struct divelog *log,
|
|
|
|
const struct xml_params *params)
|
2011-08-28 23:58:26 +00:00
|
|
|
{
|
|
|
|
xmlDoc *doc;
|
2013-03-15 17:02:14 +00:00
|
|
|
const char *res = preprocess_divelog_de(buffer);
|
2015-02-25 09:05:37 +00:00
|
|
|
int ret = 0;
|
2018-10-17 16:45:22 +00:00
|
|
|
struct parser_state state;
|
2011-08-28 23:58:26 +00:00
|
|
|
|
2022-11-12 07:57:56 +00:00
|
|
|
state.log = log;
|
2021-10-30 23:31:29 +00:00
|
|
|
state.fingerprints = &fingerprint_table; // simply use the global table for now
|
2024-03-13 22:47:05 +00:00
|
|
|
doc = xmlReadMemory(res, strlen(res), url, NULL, XML_PARSE_HUGE);
|
2017-04-16 15:12:36 +00:00
|
|
|
if (!doc)
|
2024-03-13 22:47:05 +00:00
|
|
|
doc = xmlReadMemory(res, strlen(res), url, "latin1", XML_PARSE_HUGE);
|
2017-04-16 15:12:36 +00:00
|
|
|
|
2013-03-17 05:12:23 +00:00
|
|
|
if (res != buffer)
|
|
|
|
free((char *)res);
|
|
|
|
|
2014-12-08 19:26:03 +00:00
|
|
|
if (!doc)
|
|
|
|
return report_error(translate("gettextFromC", "Failed to parse '%s'"), url);
|
|
|
|
|
2018-10-17 16:45:22 +00:00
|
|
|
reset_all(&state);
|
|
|
|
dive_start(&state);
|
2014-03-14 18:26:07 +00:00
|
|
|
doc = test_xslt_transforms(doc, params);
|
2018-10-17 16:45:22 +00:00
|
|
|
if (!traverse(xmlDocGetRootElement(doc), &state)) {
|
2015-02-25 09:05:37 +00:00
|
|
|
// we decided to give up on parsing... why?
|
|
|
|
ret = -1;
|
|
|
|
}
|
2018-10-17 16:45:22 +00:00
|
|
|
dive_end(&state);
|
2011-08-28 23:58:26 +00:00
|
|
|
xmlFreeDoc(doc);
|
2015-02-25 09:05:37 +00:00
|
|
|
return ret;
|
2011-08-28 23:58:26 +00:00
|
|
|
}
|
|
|
|
|
2015-10-03 14:29:40 +00:00
|
|
|
/*
|
2015-10-04 12:03:49 +00:00
|
|
|
* Parse a unsigned 32-bit integer in little-endian mode,
|
2015-10-03 14:29:40 +00:00
|
|
|
* that is seconds since Jan 1, 2000.
|
|
|
|
*/
|
|
|
|
static timestamp_t parse_dlf_timestamp(unsigned char *buffer)
|
|
|
|
{
|
|
|
|
timestamp_t offset;
|
|
|
|
|
2015-10-04 12:03:49 +00:00
|
|
|
offset = buffer[3];
|
2015-10-03 14:29:40 +00:00
|
|
|
offset = (offset << 8) + buffer[2];
|
|
|
|
offset = (offset << 8) + buffer[1];
|
|
|
|
offset = (offset << 8) + buffer[0];
|
|
|
|
|
|
|
|
// Jan 1, 2000 is 946684800 seconds after Jan 1, 1970, which is
|
|
|
|
// the Unix epoch date that "timestamp_t" uses.
|
|
|
|
return offset + 946684800;
|
|
|
|
}
|
|
|
|
|
2024-02-28 21:01:51 +00:00
|
|
|
extern "C" int parse_dlf_buffer(unsigned char *buffer, size_t size, struct divelog *log)
|
2014-12-27 20:10:44 +00:00
|
|
|
{
|
2014-12-28 22:38:41 +00:00
|
|
|
unsigned char *ptr = buffer;
|
2014-12-29 22:43:30 +00:00
|
|
|
unsigned char event;
|
|
|
|
bool found;
|
2014-12-28 22:38:42 +00:00
|
|
|
unsigned int time = 0;
|
2014-12-28 07:58:51 +00:00
|
|
|
int i;
|
2014-12-28 22:38:43 +00:00
|
|
|
char serial[6];
|
2018-09-12 10:39:41 +00:00
|
|
|
struct battery_status {
|
2018-09-09 18:11:34 +00:00
|
|
|
uint16_t volt1;
|
|
|
|
uint8_t percent1;
|
|
|
|
uint16_t volt2;
|
|
|
|
uint8_t percent2;
|
2018-09-12 10:39:41 +00:00
|
|
|
};
|
2018-09-12 10:41:15 +00:00
|
|
|
struct battery_status battery_start = {0, 0, 0, 0};
|
2018-09-12 10:39:41 +00:00
|
|
|
struct battery_status battery_end = {0, 0, 0, 0};
|
2018-09-10 18:31:25 +00:00
|
|
|
uint16_t o2_sensor_calibration_values[4] = {0};
|
2019-08-04 16:44:57 +00:00
|
|
|
cylinder_t *cyl;
|
2018-10-17 16:45:22 +00:00
|
|
|
struct parser_state state;
|
2014-12-27 20:10:44 +00:00
|
|
|
|
2022-11-12 07:57:56 +00:00
|
|
|
state.log = log;
|
2014-12-28 11:26:38 +00:00
|
|
|
|
2014-12-29 15:18:20 +00:00
|
|
|
// Check for the correct file magic
|
|
|
|
if (ptr[0] != 'D' || ptr[1] != 'i' || ptr[2] != 'v' || ptr[3] != 'E')
|
|
|
|
return -1;
|
|
|
|
|
2018-10-17 16:45:22 +00:00
|
|
|
dive_start(&state);
|
|
|
|
divecomputer_start(&state);
|
2014-12-28 22:38:43 +00:00
|
|
|
|
2018-10-17 16:45:22 +00:00
|
|
|
state.cur_dc->model = strdup("DLF import");
|
2014-12-28 22:38:43 +00:00
|
|
|
// (ptr[7] << 8) + ptr[6] Is "Serial"
|
|
|
|
snprintf(serial, sizeof(serial), "%d", (ptr[7] << 8) + ptr[6]);
|
2018-10-17 16:45:22 +00:00
|
|
|
state.cur_dc->serial = strdup(serial);
|
|
|
|
state.cur_dc->when = parse_dlf_timestamp(ptr + 8);
|
|
|
|
state.cur_dive->when = state.cur_dc->when;
|
2014-12-28 22:38:43 +00:00
|
|
|
|
2018-10-17 16:45:22 +00:00
|
|
|
state.cur_dc->duration.seconds = ((ptr[14] & 0xFE) << 16) + (ptr[13] << 8) + ptr[12];
|
2014-12-28 22:38:43 +00:00
|
|
|
|
2015-01-23 23:29:33 +00:00
|
|
|
// ptr[14] >> 1 is scrubber used in %
|
|
|
|
|
|
|
|
// 3 bit dive type
|
2022-08-20 12:31:39 +00:00
|
|
|
switch((ptr[15] & 0x38) >> 3) {
|
2015-01-23 23:29:33 +00:00
|
|
|
case 0: // unknown
|
|
|
|
case 1:
|
2018-10-17 16:45:22 +00:00
|
|
|
state.cur_dc->divemode = OC;
|
2015-01-23 23:29:33 +00:00
|
|
|
break;
|
|
|
|
case 2:
|
2018-10-17 16:45:22 +00:00
|
|
|
state.cur_dc->divemode = CCR;
|
2015-01-23 23:29:33 +00:00
|
|
|
break;
|
|
|
|
case 3:
|
2018-10-17 16:45:22 +00:00
|
|
|
state.cur_dc->divemode = CCR; // mCCR
|
2015-01-23 23:29:33 +00:00
|
|
|
break;
|
|
|
|
case 4:
|
2018-10-17 16:45:22 +00:00
|
|
|
state.cur_dc->divemode = FREEDIVE;
|
2015-01-23 23:29:33 +00:00
|
|
|
break;
|
|
|
|
case 5:
|
2018-10-17 16:45:22 +00:00
|
|
|
state.cur_dc->divemode = OC; // Gauge
|
2015-01-23 23:29:33 +00:00
|
|
|
break;
|
|
|
|
case 6:
|
2018-10-17 16:45:22 +00:00
|
|
|
state.cur_dc->divemode = PSCR; // ASCR
|
2015-01-23 23:29:33 +00:00
|
|
|
break;
|
|
|
|
case 7:
|
2018-10-17 16:45:22 +00:00
|
|
|
state.cur_dc->divemode = PSCR;
|
2015-01-23 23:29:33 +00:00
|
|
|
break;
|
|
|
|
}
|
2014-12-28 22:38:43 +00:00
|
|
|
|
2018-10-17 16:45:22 +00:00
|
|
|
state.cur_dc->maxdepth.mm = ((ptr[21] << 8) + ptr[20]) * 10;
|
|
|
|
state.cur_dc->surface_pressure.mbar = ((ptr[25] << 8) + ptr[24]) / 10;
|
2014-12-28 22:38:43 +00:00
|
|
|
|
2018-09-10 18:29:20 +00:00
|
|
|
// Declare initial mix as first cylinder
|
2019-08-04 16:44:57 +00:00
|
|
|
cyl = get_or_create_cylinder(state.cur_dive, 0);
|
|
|
|
cyl->gasmix.o2.permille = ptr[26] * 10;
|
|
|
|
cyl->gasmix.he.permille = ptr[27] * 10;
|
2018-09-10 18:29:20 +00:00
|
|
|
|
2014-12-28 22:38:43 +00:00
|
|
|
/* Done with parsing what we know about the dive header */
|
|
|
|
ptr += 32;
|
2014-12-27 20:10:44 +00:00
|
|
|
|
2015-01-06 12:23:31 +00:00
|
|
|
// We're going to interpret ppO2 saved as a sensor value in these modes.
|
2018-10-17 16:45:22 +00:00
|
|
|
if (state.cur_dc->divemode == CCR || state.cur_dc->divemode == PSCR)
|
|
|
|
state.cur_dc->no_o2sensors = 1;
|
2015-01-06 12:23:31 +00:00
|
|
|
|
2017-08-07 18:39:33 +00:00
|
|
|
for (; ptr < buffer + size; ptr += 16) {
|
2014-12-28 22:38:42 +00:00
|
|
|
time = ((ptr[0] >> 4) & 0x0f) +
|
|
|
|
((ptr[1] << 4) & 0xff0) +
|
2016-04-25 18:23:22 +00:00
|
|
|
((ptr[2] << 12) & 0x1f000);
|
2014-12-27 20:10:44 +00:00
|
|
|
event = ptr[0] & 0x0f;
|
2014-12-29 22:43:30 +00:00
|
|
|
switch (event) {
|
|
|
|
case 0:
|
|
|
|
/* Regular sample */
|
2018-10-17 16:45:22 +00:00
|
|
|
sample_start(&state);
|
|
|
|
state.cur_sample->time.seconds = time;
|
|
|
|
state.cur_sample->depth.mm = ((ptr[5] << 8) + ptr[4]) * 10;
|
2015-01-05 21:59:18 +00:00
|
|
|
// Crazy precision on these stored values...
|
|
|
|
// Only store value if we're in CCR/PSCR mode,
|
|
|
|
// because we rather calculate ppo2 our selfs.
|
2018-10-17 16:45:22 +00:00
|
|
|
if (state.cur_dc->divemode == CCR || state.cur_dc->divemode == PSCR)
|
|
|
|
state.cur_sample->o2sensor[0].mbar = ((ptr[7] << 8) + ptr[6]) / 10;
|
2017-08-07 21:42:03 +00:00
|
|
|
|
|
|
|
// In some test files, ndl / tts / temp is bogus if this bits are 1
|
|
|
|
// flag bits in ptr[11] & 0xF0 is probably involved to,
|
|
|
|
if ((ptr[2] >> 5) != 1) {
|
|
|
|
// NDL in minutes, 10 bit
|
2018-10-17 16:45:22 +00:00
|
|
|
state.cur_sample->ndl.seconds = (((ptr[9] & 0x03) << 8) + ptr[8]) * 60;
|
2017-08-07 21:42:03 +00:00
|
|
|
// TTS in minutes, 10 bit
|
2018-10-17 16:45:22 +00:00
|
|
|
state.cur_sample->tts.seconds = (((ptr[10] & 0x0F) << 6) + (ptr[9] >> 2)) * 60;
|
2017-08-07 21:42:03 +00:00
|
|
|
// Temperature in 1/10 C, 10 bit signed
|
2018-10-17 16:45:22 +00:00
|
|
|
state.cur_sample->temperature.mkelvin = ((ptr[11] & 0x20) ? -1 : 1) * (((ptr[11] & 0x1F) << 4) + (ptr[10] >> 4)) * 100 + ZERO_C_IN_MKELVIN;
|
2017-08-07 21:42:03 +00:00
|
|
|
}
|
2018-10-17 16:45:22 +00:00
|
|
|
state.cur_sample->stopdepth.mm = ((ptr[13] << 8) + ptr[12]) * 10;
|
|
|
|
if (state.cur_sample->stopdepth.mm)
|
|
|
|
state.cur_sample->in_deco = true;
|
2015-01-23 23:29:37 +00:00
|
|
|
//ptr[14] is helium content, always zero?
|
2017-08-07 21:42:03 +00:00
|
|
|
//ptr[15] is setpoint, what the computer thinks you should aim for?
|
2018-10-17 16:45:22 +00:00
|
|
|
sample_end(&state);
|
2014-12-29 22:43:30 +00:00
|
|
|
break;
|
2015-01-23 16:15:09 +00:00
|
|
|
case 1: /* dive event */
|
|
|
|
case 2: /* automatic parameter change */
|
|
|
|
case 3: /* diver error */
|
|
|
|
case 4: /* internal error */
|
|
|
|
case 5: /* device activity log */
|
2017-10-02 15:18:47 +00:00
|
|
|
//Event 18 is a button press. Lets ingore that event.
|
2017-08-15 13:21:09 +00:00
|
|
|
if (ptr[4] == 18)
|
2017-08-15 13:14:51 +00:00
|
|
|
continue;
|
2017-10-02 15:18:47 +00:00
|
|
|
|
2018-10-17 16:45:22 +00:00
|
|
|
event_start(&state);
|
|
|
|
state.cur_event.time.seconds = time;
|
2014-12-29 22:43:30 +00:00
|
|
|
switch (ptr[4]) {
|
2014-12-29 22:43:33 +00:00
|
|
|
case 1:
|
2018-10-17 16:45:22 +00:00
|
|
|
strcpy(state.cur_event.name, "Setpoint Manual");
|
|
|
|
state.cur_event.value = ptr[6];
|
|
|
|
sample_start(&state);
|
|
|
|
state.cur_sample->setpoint.mbar = ptr[6] * 10;
|
|
|
|
sample_end(&state);
|
2014-12-29 22:43:33 +00:00
|
|
|
break;
|
|
|
|
case 2:
|
2018-10-17 16:45:22 +00:00
|
|
|
strcpy(state.cur_event.name, "Setpoint Auto");
|
|
|
|
state.cur_event.value = ptr[6];
|
|
|
|
sample_start(&state);
|
|
|
|
state.cur_sample->setpoint.mbar = ptr[6] * 10;
|
|
|
|
sample_end(&state);
|
2014-12-29 22:43:33 +00:00
|
|
|
switch (ptr[7]) {
|
|
|
|
case 0:
|
2018-10-17 16:45:22 +00:00
|
|
|
strcat(state.cur_event.name, " Manual");
|
2014-12-29 22:43:33 +00:00
|
|
|
break;
|
|
|
|
case 1:
|
2018-10-17 16:45:22 +00:00
|
|
|
strcat(state.cur_event.name, " Auto Start");
|
2014-12-29 22:43:33 +00:00
|
|
|
break;
|
|
|
|
case 2:
|
2018-10-17 16:45:22 +00:00
|
|
|
strcat(state.cur_event.name, " Auto Hypox");
|
2014-12-29 22:43:33 +00:00
|
|
|
break;
|
|
|
|
case 3:
|
2018-10-17 16:45:22 +00:00
|
|
|
strcat(state.cur_event.name, " Auto Timeout");
|
2014-12-29 22:43:33 +00:00
|
|
|
break;
|
|
|
|
case 4:
|
2018-10-17 16:45:22 +00:00
|
|
|
strcat(state.cur_event.name, " Auto Ascent");
|
2014-12-29 22:43:33 +00:00
|
|
|
break;
|
|
|
|
case 5:
|
2018-10-17 16:45:22 +00:00
|
|
|
strcat(state.cur_event.name, " Auto Stall");
|
2014-12-29 22:43:33 +00:00
|
|
|
break;
|
|
|
|
case 6:
|
2018-10-17 16:45:22 +00:00
|
|
|
strcat(state.cur_event.name, " Auto SP Low");
|
2014-12-29 22:43:33 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 3:
|
2015-01-23 16:15:08 +00:00
|
|
|
// obsolete
|
2018-10-17 16:45:22 +00:00
|
|
|
strcpy(state.cur_event.name, "OC");
|
2014-12-29 22:43:33 +00:00
|
|
|
break;
|
|
|
|
case 4:
|
2015-01-23 16:15:08 +00:00
|
|
|
// obsolete
|
2018-10-17 16:45:22 +00:00
|
|
|
strcpy(state.cur_event.name, "CCR");
|
2014-12-29 22:43:33 +00:00
|
|
|
break;
|
2014-12-28 07:58:51 +00:00
|
|
|
case 5:
|
2018-10-17 16:45:22 +00:00
|
|
|
strcpy(state.cur_event.name, "gaschange");
|
|
|
|
state.cur_event.type = SAMPLE_EVENT_GASCHANGE2;
|
|
|
|
state.cur_event.value = ptr[7] << 8 ^ ptr[6];
|
2014-12-28 07:58:51 +00:00
|
|
|
|
|
|
|
found = false;
|
2019-08-04 16:44:57 +00:00
|
|
|
for (i = 0; i < state.cur_dive->cylinders.nr; ++i) {
|
2019-08-04 20:13:49 +00:00
|
|
|
const cylinder_t *cyl = get_cylinder(state.cur_dive, i);
|
2019-08-04 16:44:57 +00:00
|
|
|
if (cyl->gasmix.o2.permille == ptr[6] * 10 && cyl->gasmix.he.permille == ptr[7] * 10) {
|
2014-12-28 07:58:51 +00:00
|
|
|
found = true;
|
|
|
|
break;
|
2015-06-22 05:00:21 +00:00
|
|
|
}
|
2014-12-28 07:58:51 +00:00
|
|
|
}
|
|
|
|
if (!found) {
|
2019-08-04 16:59:14 +00:00
|
|
|
cyl = cylinder_start(&state);
|
2019-08-04 16:44:57 +00:00
|
|
|
cyl->gasmix.o2.permille = ptr[6] * 10;
|
|
|
|
cyl->gasmix.he.permille = ptr[7] * 10;
|
2018-10-17 16:45:22 +00:00
|
|
|
cylinder_end(&state);
|
2019-08-04 16:44:57 +00:00
|
|
|
state.cur_event.gas.index = state.cur_dive->cylinders.nr - 1;
|
2014-12-30 16:05:51 +00:00
|
|
|
} else {
|
2018-10-17 16:45:22 +00:00
|
|
|
state.cur_event.gas.index = i;
|
2014-12-28 07:58:51 +00:00
|
|
|
}
|
|
|
|
break;
|
2014-12-28 22:38:44 +00:00
|
|
|
case 6:
|
2018-10-17 16:45:22 +00:00
|
|
|
strcpy(state.cur_event.name, "Start");
|
2014-12-29 22:43:33 +00:00
|
|
|
break;
|
|
|
|
case 7:
|
2018-10-17 16:45:22 +00:00
|
|
|
strcpy(state.cur_event.name, "Too Fast");
|
2014-12-29 22:43:33 +00:00
|
|
|
break;
|
|
|
|
case 8:
|
2018-10-17 16:45:22 +00:00
|
|
|
strcpy(state.cur_event.name, "Above Ceiling");
|
2014-12-29 22:43:33 +00:00
|
|
|
break;
|
|
|
|
case 9:
|
2018-10-17 16:45:22 +00:00
|
|
|
strcpy(state.cur_event.name, "Toxic");
|
2014-12-29 22:43:33 +00:00
|
|
|
break;
|
|
|
|
case 10:
|
2018-10-17 16:45:22 +00:00
|
|
|
strcpy(state.cur_event.name, "Hypox");
|
2014-12-29 22:43:33 +00:00
|
|
|
break;
|
|
|
|
case 11:
|
2018-10-17 16:45:22 +00:00
|
|
|
strcpy(state.cur_event.name, "Critical");
|
2014-12-29 22:43:33 +00:00
|
|
|
break;
|
|
|
|
case 12:
|
2018-10-17 16:45:22 +00:00
|
|
|
strcpy(state.cur_event.name, "Sensor Disabled");
|
2014-12-29 22:43:33 +00:00
|
|
|
break;
|
|
|
|
case 13:
|
2018-10-17 16:45:22 +00:00
|
|
|
strcpy(state.cur_event.name, "Sensor Enabled");
|
2014-12-29 22:43:33 +00:00
|
|
|
break;
|
|
|
|
case 14:
|
2018-10-17 16:45:22 +00:00
|
|
|
strcpy(state.cur_event.name, "O2 Backup");
|
2014-12-29 22:43:33 +00:00
|
|
|
break;
|
|
|
|
case 15:
|
2018-10-17 16:45:22 +00:00
|
|
|
strcpy(state.cur_event.name, "Peer Down");
|
2014-12-29 22:43:33 +00:00
|
|
|
break;
|
|
|
|
case 16:
|
2018-10-17 16:45:22 +00:00
|
|
|
strcpy(state.cur_event.name, "HS Down");
|
2014-12-29 22:43:33 +00:00
|
|
|
break;
|
|
|
|
case 17:
|
2018-10-17 16:45:22 +00:00
|
|
|
strcpy(state.cur_event.name, "Inconsistent");
|
2014-12-29 22:43:33 +00:00
|
|
|
break;
|
|
|
|
case 18:
|
2017-08-28 11:32:54 +00:00
|
|
|
// key pressed - It should never get in here
|
2017-10-02 15:18:47 +00:00
|
|
|
// as we ingored it at the parent 'case 5'.
|
2014-12-29 22:43:33 +00:00
|
|
|
break;
|
|
|
|
case 19:
|
2015-01-23 16:15:08 +00:00
|
|
|
// obsolete
|
2018-10-17 16:45:22 +00:00
|
|
|
strcpy(state.cur_event.name, "SCR");
|
2014-12-29 22:43:33 +00:00
|
|
|
break;
|
|
|
|
case 20:
|
2018-10-17 16:45:22 +00:00
|
|
|
strcpy(state.cur_event.name, "Above Stop");
|
2014-12-29 22:43:33 +00:00
|
|
|
break;
|
|
|
|
case 21:
|
2018-10-17 16:45:22 +00:00
|
|
|
strcpy(state.cur_event.name, "Safety Miss");
|
2014-12-29 22:43:33 +00:00
|
|
|
break;
|
|
|
|
case 22:
|
2018-10-17 16:45:22 +00:00
|
|
|
strcpy(state.cur_event.name, "Fatal");
|
2014-12-29 22:43:33 +00:00
|
|
|
break;
|
|
|
|
case 23:
|
2018-10-17 16:45:22 +00:00
|
|
|
strcpy(state.cur_event.name, "gaschange");
|
|
|
|
state.cur_event.type = SAMPLE_EVENT_GASCHANGE2;
|
|
|
|
state.cur_event.value = ptr[7] << 8 ^ ptr[6];
|
|
|
|
event_end(&state);
|
2014-12-29 22:43:33 +00:00
|
|
|
break;
|
|
|
|
case 24:
|
2018-10-17 16:45:22 +00:00
|
|
|
strcpy(state.cur_event.name, "gaschange");
|
|
|
|
state.cur_event.type = SAMPLE_EVENT_GASCHANGE2;
|
|
|
|
state.cur_event.value = ptr[7] << 8 ^ ptr[6];
|
|
|
|
event_end(&state);
|
2014-12-29 22:43:33 +00:00
|
|
|
// This is both a mode change and a gas change event
|
|
|
|
// so we encode it as two separate events.
|
2018-10-17 16:45:22 +00:00
|
|
|
event_start(&state);
|
|
|
|
strcpy(state.cur_event.name, "Change Mode");
|
2014-12-29 22:43:33 +00:00
|
|
|
switch (ptr[8]) {
|
|
|
|
case 1:
|
2018-10-17 16:45:22 +00:00
|
|
|
strcat(state.cur_event.name, ": OC");
|
2014-12-29 22:43:33 +00:00
|
|
|
break;
|
|
|
|
case 2:
|
2018-10-17 16:45:22 +00:00
|
|
|
strcat(state.cur_event.name, ": CCR");
|
2014-12-29 22:43:33 +00:00
|
|
|
break;
|
|
|
|
case 3:
|
2018-10-17 16:45:22 +00:00
|
|
|
strcat(state.cur_event.name, ": mCCR");
|
2014-12-29 22:43:33 +00:00
|
|
|
break;
|
|
|
|
case 4:
|
2018-10-17 16:45:22 +00:00
|
|
|
strcat(state.cur_event.name, ": Free");
|
2014-12-29 22:43:33 +00:00
|
|
|
break;
|
|
|
|
case 5:
|
2018-10-17 16:45:22 +00:00
|
|
|
strcat(state.cur_event.name, ": Gauge");
|
2014-12-29 22:43:33 +00:00
|
|
|
break;
|
|
|
|
case 6:
|
2018-10-17 16:45:22 +00:00
|
|
|
strcat(state.cur_event.name, ": ASCR");
|
2014-12-29 22:43:33 +00:00
|
|
|
break;
|
|
|
|
case 7:
|
2018-10-17 16:45:22 +00:00
|
|
|
strcat(state.cur_event.name, ": PSCR");
|
2014-12-29 22:43:33 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2018-10-17 16:45:22 +00:00
|
|
|
event_end(&state);
|
2014-12-29 22:43:33 +00:00
|
|
|
break;
|
2015-01-23 16:15:08 +00:00
|
|
|
case 25:
|
2018-09-10 11:31:14 +00:00
|
|
|
// uint16_t solenoid_bitmap = (ptr[7] << 8) + (ptr[6] << 0);
|
|
|
|
// uint32_t time = (ptr[11] << 24) + (ptr[10] << 16) + (ptr[9] << 8) + (ptr[8] << 0);
|
2018-10-17 16:45:22 +00:00
|
|
|
snprintf(state.cur_event.name, MAX_EVENT_NAME, "CCR O2 solenoid %s", ptr[12] ? "opened": "closed");
|
2015-01-23 16:15:08 +00:00
|
|
|
break;
|
|
|
|
case 26:
|
2018-10-17 16:45:22 +00:00
|
|
|
strcpy(state.cur_event.name, "User mark");
|
2015-01-23 16:15:08 +00:00
|
|
|
break;
|
2014-12-29 22:43:33 +00:00
|
|
|
case 27:
|
2018-10-17 16:45:22 +00:00
|
|
|
snprintf(state.cur_event.name, MAX_EVENT_NAME, "%sGF Switch (%d/%d)", ptr[6] ? "Bailout, ": "", ptr[7], ptr[8]);
|
2014-12-29 22:43:33 +00:00
|
|
|
break;
|
|
|
|
case 28:
|
2018-10-17 16:45:22 +00:00
|
|
|
strcpy(state.cur_event.name, "Peer Up");
|
2014-12-29 22:43:33 +00:00
|
|
|
break;
|
|
|
|
case 29:
|
2018-10-17 16:45:22 +00:00
|
|
|
strcpy(state.cur_event.name, "HS Up");
|
2014-12-29 22:43:33 +00:00
|
|
|
break;
|
|
|
|
case 30:
|
2018-10-17 16:45:22 +00:00
|
|
|
snprintf(state.cur_event.name, MAX_EVENT_NAME, "CNS %d%%", ptr[6]);
|
2014-12-28 22:38:44 +00:00
|
|
|
break;
|
2014-12-28 07:58:51 +00:00
|
|
|
default:
|
2014-12-29 22:43:33 +00:00
|
|
|
// No values above 30 had any description
|
2014-12-29 22:43:30 +00:00
|
|
|
break;
|
2014-12-28 07:58:51 +00:00
|
|
|
}
|
2018-10-17 16:45:22 +00:00
|
|
|
event_end(&state);
|
2014-12-29 22:43:30 +00:00
|
|
|
break;
|
2015-01-23 16:15:09 +00:00
|
|
|
case 6:
|
|
|
|
/* device configuration */
|
2018-09-10 17:40:54 +00:00
|
|
|
switch (((ptr[3] & 0x7f) << 3) + ((ptr[2] & 0xe0) >> 5)) {
|
|
|
|
// Buffer to print extra string into
|
|
|
|
char config_buf[256];
|
|
|
|
// Local variables to temporary decode into
|
|
|
|
struct tm tm;
|
2024-02-28 21:01:51 +00:00
|
|
|
const char *device;
|
|
|
|
const char *deep_stops;
|
2018-09-10 17:40:54 +00:00
|
|
|
case 0: // TEST_CCR_FULL_1
|
|
|
|
utc_mkdate(parse_dlf_timestamp(ptr + 12), &tm);
|
|
|
|
snprintf(config_buf, sizeof(config_buf), "START=%04u-%02u-%02u %02u:%02u:%02u,TEST=%02X%02X%02X%02X,RESULT=%02X%02X%02X%02X", tm.tm_year, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec, ptr[7], ptr[6], ptr[5], ptr[4], ptr[11], ptr[10], ptr[9], ptr[8]);
|
2018-10-17 16:45:22 +00:00
|
|
|
add_extra_data(state.cur_dc, "TEST_CCR_FULL_1", config_buf);
|
2018-09-10 17:40:54 +00:00
|
|
|
break;
|
|
|
|
case 1: // TEST_CCR_PARTIAL_1
|
|
|
|
utc_mkdate(parse_dlf_timestamp(ptr + 12), &tm);
|
|
|
|
snprintf(config_buf, sizeof(config_buf), "START=%04u-%02u-%02u %02u:%02u:%02u,TEST=%02X%02X%02X%02X,RESULT=%02X%02X%02X%02X", tm.tm_year, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec, ptr[7], ptr[6], ptr[5], ptr[4], ptr[11], ptr[10], ptr[9], ptr[8]);
|
2018-10-17 16:45:22 +00:00
|
|
|
add_extra_data(state.cur_dc, "TEST_CCR_PARTIAL_1", config_buf);
|
2018-09-10 17:40:54 +00:00
|
|
|
break;
|
|
|
|
case 2: // CFG_OXYGEN_CALIBRATION
|
|
|
|
utc_mkdate(parse_dlf_timestamp(ptr + 12), &tm);
|
2018-09-10 18:31:25 +00:00
|
|
|
o2_sensor_calibration_values[0] = (ptr[5] << 8) + ptr[4];
|
|
|
|
o2_sensor_calibration_values[1] = (ptr[7] << 8) + ptr[6];
|
|
|
|
o2_sensor_calibration_values[2] = (ptr[9] << 8) + ptr[8];
|
|
|
|
o2_sensor_calibration_values[3] = (ptr[11] << 8) + ptr[10];
|
|
|
|
snprintf(config_buf, sizeof(config_buf), "%04u,%04u,%04u,%04u,TIME=%04u-%02u-%02u %02u:%02u:%02u", o2_sensor_calibration_values[0], o2_sensor_calibration_values[1], o2_sensor_calibration_values[2], o2_sensor_calibration_values[3], tm.tm_year, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec);
|
2018-10-17 16:45:22 +00:00
|
|
|
add_extra_data(state.cur_dc, "CFG_OXYGEN_CALIBRATION", config_buf);
|
2018-09-10 17:40:54 +00:00
|
|
|
break;
|
|
|
|
case 3: // CFG_SERIAL
|
|
|
|
snprintf(config_buf, sizeof(config_buf), "PRODUCT=%c%c%c%c,SERIAL=%c%c%c%c%c%c%c%c", ptr[4], ptr[5], ptr[6], ptr[7], ptr[8], ptr[9], ptr[10], ptr[11], ptr[12], ptr[13], ptr[14], ptr[15]);
|
2018-10-17 16:45:22 +00:00
|
|
|
add_extra_data(state.cur_dc, "CFG_SERIAL", config_buf);
|
2018-09-10 17:40:54 +00:00
|
|
|
break;
|
|
|
|
case 4: // CFG_CONFIG_DECO
|
|
|
|
switch ((ptr[5] & 0xC0) >> 6) {
|
|
|
|
case 0:
|
|
|
|
deep_stops = "none";
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
deep_stops = "Pyle";
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
deep_stops = "Sladek";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
deep_stops = "unknown";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
snprintf(config_buf, sizeof(config_buf), "%s,%s,%s,safety stop required=%s,last_stop=%s,deco_algorithm=%s,stop_rounding=%u,deep_stops=%s", (ptr[4] & 0x80) ? "imperial" : "metric", (ptr[4] & 0x40) ? "sea" : "fresh", (ptr[4] & 0x30) ? "stops" : "ceiling", (ptr[4] & 0x10) ? "yes" : "no", (ptr[4] & 0x08) ? "6m" : "3m", (ptr[4] & 0x04) ? "VPM" : "Buhlmann+GF", (ptr[4] & 0x03) ? (ptr[4] & 0x03) * 30 : 1, deep_stops);
|
2018-10-17 16:45:22 +00:00
|
|
|
add_extra_data(state.cur_dc, "CFG_CONFIG_DECO part 1", config_buf);
|
2018-09-10 17:40:54 +00:00
|
|
|
snprintf(config_buf, sizeof(config_buf), "deep_stop_len=%u min,gas_switch_len=%u min,gf_low=%u,gf_high=%u,gf_low_bailout=%u,gf_high_bailout=%u,ppO2_low=%4.2f,ppO2_high=%4.2f", (ptr[5] & 0x38) >> 3, ptr[5] & 0x07, ptr[6], ptr[7], ptr[8], ptr[9], ptr[10] / 100.0f, ptr[11] / 100.0f);
|
2018-10-17 16:45:22 +00:00
|
|
|
add_extra_data(state.cur_dc, "CFG_CONFIG_DECO part 2", config_buf);
|
2018-09-10 17:40:54 +00:00
|
|
|
snprintf(config_buf, sizeof(config_buf), "alarm_global=%u,alarm_cns=%u,alarm_ppO2=%u,alarm_ceiling=%u,alarm_stop_miss=%u,alarm_decentrate=%u,alarm_ascentrate=%u", (ptr[12] & 0x80) >> 7, (ptr[12] & 0x40) >> 6, (ptr[12] & 0x20) >> 5, (ptr[12] & 0x10) >> 4, (ptr[12] & 0x08) >> 3, (ptr[12] & 0x04) >> 2, (ptr[12] & 0x02) >> 1);
|
2018-10-17 16:45:22 +00:00
|
|
|
add_extra_data(state.cur_dc, "CFG_CONFIG_DECO part 3", config_buf);
|
2018-09-10 17:40:54 +00:00
|
|
|
break;
|
|
|
|
case 5: // CFG_VERSION
|
|
|
|
switch (ptr[4]) {
|
|
|
|
case 0:
|
|
|
|
device = "FREEDOM";
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
device = "LIBERTY_CU";
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
device = "LIBERTY_HS";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
device = "UNKNOWN";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
snprintf(config_buf, sizeof(config_buf), "DEVICE=%s,HW=%d.%d,FW=%d.%d.%d.%d,FLAGS=%04X", device, ptr[5], ptr[6], ptr[7], ptr[8], ptr[9], (ptr[15] << 24) + (ptr[14] << 16) + (ptr[13] << 8) + (ptr[12]), (ptr[11] << 8) + ptr[10]);
|
2018-10-17 16:45:22 +00:00
|
|
|
add_extra_data(state.cur_dc, "CFG_VERSION", config_buf);
|
2018-09-10 17:40:54 +00:00
|
|
|
break;
|
|
|
|
}
|
2015-01-23 16:15:09 +00:00
|
|
|
break;
|
2014-12-29 22:43:32 +00:00
|
|
|
case 7:
|
2015-01-23 16:15:09 +00:00
|
|
|
/* measure record */
|
2017-08-07 22:00:36 +00:00
|
|
|
switch (ptr[2] >> 5) {
|
|
|
|
case 1:
|
2018-09-12 10:41:15 +00:00
|
|
|
/* Record starting battery level */
|
|
|
|
if (!battery_start.volt1 && !battery_start.volt2) {
|
|
|
|
battery_start.volt1 = (ptr[5] << 8) + ptr[4];
|
|
|
|
battery_start.percent1 = ptr[6];
|
|
|
|
battery_start.volt2 = (ptr[9] << 8) + ptr[8];
|
|
|
|
battery_start.percent2 = ptr[10];
|
|
|
|
}
|
|
|
|
|
2018-09-09 18:11:34 +00:00
|
|
|
/* Measure Battery, recording the last reading only */
|
2018-09-12 10:39:41 +00:00
|
|
|
battery_end.volt1 = (ptr[5] << 8) + ptr[4];
|
|
|
|
battery_end.percent1 = ptr[6];
|
|
|
|
battery_end.volt2 = (ptr[9] << 8) + ptr[8];
|
|
|
|
battery_end.percent2 = ptr[10];
|
2018-09-09 18:11:34 +00:00
|
|
|
break;
|
2018-09-09 18:29:35 +00:00
|
|
|
case 2:
|
|
|
|
/* Measure He */
|
|
|
|
//printf("%ds he2 cells(0.01 mV): %d %d\n", time, (ptr[5] << 8) + ptr[4], (ptr[9] << 8) + ptr[8]);
|
|
|
|
break;
|
2017-08-07 22:00:36 +00:00
|
|
|
case 3:
|
|
|
|
/* Measure Oxygen */
|
2018-09-09 18:29:35 +00:00
|
|
|
//printf("%d s: o2 cells(0.01 mV): %d %d %d %d\n", time, (ptr[5] << 8) + ptr[4], (ptr[7] << 8) + ptr[6], (ptr[9] << 8) + ptr[8], (ptr[11] << 8) + ptr[10]);
|
2018-09-10 18:31:25 +00:00
|
|
|
// [Pa/mV] coeficient O2
|
|
|
|
// 100 Pa == 1 mbar
|
2018-10-17 16:45:22 +00:00
|
|
|
sample_start(&state);
|
|
|
|
state.cur_sample->time.seconds = time;
|
|
|
|
state.cur_sample->o2sensor[0].mbar = ( ((ptr[5] << 8) + ptr[4]) * o2_sensor_calibration_values[0]) / 10000;
|
|
|
|
state.cur_sample->o2sensor[1].mbar = ( ((ptr[7] << 8) + ptr[6]) * o2_sensor_calibration_values[1]) / 10000;
|
|
|
|
state.cur_sample->o2sensor[2].mbar = ( ((ptr[9] << 8) + ptr[8]) * o2_sensor_calibration_values[2]) / 10000;
|
2024-01-20 23:35:44 +00:00
|
|
|
state.cur_sample->o2sensor[3].mbar = ( ((ptr[11] << 8) + ptr[10]) * o2_sensor_calibration_values[3]) / 10000;
|
2018-10-17 16:45:22 +00:00
|
|
|
sample_end(&state);
|
2017-08-07 22:00:36 +00:00
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
/* Measure GPS */
|
2018-10-17 16:45:22 +00:00
|
|
|
state.cur_location.lat.udeg = (int)((ptr[7] << 24) + (ptr[6] << 16) + (ptr[5] << 8) + (ptr[4] << 0));
|
|
|
|
state.cur_location.lon.udeg = (int)((ptr[11] << 24) + (ptr[10] << 16) + (ptr[9] << 8) + (ptr[8] << 0));
|
2022-11-12 07:57:56 +00:00
|
|
|
add_dive_to_dive_site(state.cur_dive, create_dive_site_with_gps("DLF imported", &state.cur_location, state.log->sites));
|
2017-08-07 22:00:36 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2014-12-29 22:43:32 +00:00
|
|
|
break;
|
2018-09-09 18:37:39 +00:00
|
|
|
case 8:
|
|
|
|
/* Deco event */
|
|
|
|
break;
|
2014-12-29 22:43:30 +00:00
|
|
|
default:
|
|
|
|
/* Unknown... */
|
|
|
|
break;
|
2014-12-27 20:10:44 +00:00
|
|
|
}
|
|
|
|
}
|
2018-09-09 18:11:34 +00:00
|
|
|
|
2018-09-12 10:41:15 +00:00
|
|
|
/* Recording the starting battery status to extra data */
|
|
|
|
if (battery_start.volt1) {
|
2024-03-01 22:27:55 +00:00
|
|
|
std::string str = format_string_std("%dmV (%d%%)", battery_start.volt1, battery_start.percent1);
|
|
|
|
add_extra_data(state.cur_dc, "Battery 1 (start)", str.c_str());
|
2018-09-12 10:41:15 +00:00
|
|
|
|
2024-03-01 22:27:55 +00:00
|
|
|
str = format_string_std("%dmV (%d%%)", battery_start.volt2, battery_start.percent2);
|
|
|
|
add_extra_data(state.cur_dc, "Battery 2 (start)", str.c_str());
|
2018-09-12 10:41:15 +00:00
|
|
|
}
|
|
|
|
|
2018-09-09 18:11:34 +00:00
|
|
|
/* Recording the ending battery status to extra data */
|
2018-09-12 10:39:41 +00:00
|
|
|
if (battery_end.volt1) {
|
2024-03-01 22:27:55 +00:00
|
|
|
std::string str = format_string_std("%dmV (%d%%)", battery_end.volt1, battery_end.percent1);
|
|
|
|
add_extra_data(state.cur_dc, "Battery 1 (end)", str.c_str());
|
2018-09-09 18:11:34 +00:00
|
|
|
|
2024-03-01 22:27:55 +00:00
|
|
|
str = format_string_std("%dmV (%d%%)", battery_end.volt2, battery_end.percent2);
|
|
|
|
add_extra_data(state.cur_dc, "Battery 2 (end)", str.c_str());
|
2018-09-09 18:11:34 +00:00
|
|
|
}
|
|
|
|
|
2018-10-17 16:45:22 +00:00
|
|
|
divecomputer_end(&state);
|
|
|
|
dive_end(&state);
|
2014-12-28 14:51:28 +00:00
|
|
|
return 0;
|
2014-12-27 20:10:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-02-28 21:01:51 +00:00
|
|
|
extern "C" void parse_xml_init(void)
|
2011-08-30 23:28:59 +00:00
|
|
|
{
|
2011-08-28 23:58:26 +00:00
|
|
|
LIBXML_TEST_VERSION
|
|
|
|
}
|
2011-11-05 10:39:17 +00:00
|
|
|
|
2024-02-28 21:01:51 +00:00
|
|
|
extern "C" void parse_xml_exit(void)
|
2012-09-18 15:33:55 +00:00
|
|
|
{
|
|
|
|
xmlCleanupParser();
|
|
|
|
}
|
|
|
|
|
2011-11-16 05:12:43 +00:00
|
|
|
static struct xslt_files {
|
|
|
|
const char *root;
|
|
|
|
const char *file;
|
2014-02-08 12:00:54 +00:00
|
|
|
const char *attribute;
|
2011-11-16 05:12:43 +00:00
|
|
|
} xslt_files[] = {
|
2014-02-16 23:42:56 +00:00
|
|
|
{ "SUUNTO", "SuuntoSDM.xslt", NULL },
|
|
|
|
{ "Dive", "SuuntoDM4.xslt", "xmlns" },
|
|
|
|
{ "Dive", "shearwater.xslt", "version" },
|
|
|
|
{ "JDiveLog", "jdivelog2subsurface.xslt", NULL },
|
|
|
|
{ "dives", "MacDive.xslt", NULL },
|
|
|
|
{ "DIVELOGSDATA", "divelogs.xslt", NULL },
|
|
|
|
{ "uddf", "uddf.xslt", NULL },
|
|
|
|
{ "UDDF", "uddf.xslt", NULL },
|
|
|
|
{ "profile", "udcf.xslt", NULL },
|
|
|
|
{ "Divinglog", "DivingLog.xslt", NULL },
|
|
|
|
{ "csv", "csv2xml.xslt", NULL },
|
|
|
|
{ "sensuscsv", "sensuscsv.xslt", NULL },
|
2014-12-26 14:11:38 +00:00
|
|
|
{ "SubsurfaceCSV", "subsurfacecsv.xslt", NULL },
|
2014-02-16 23:42:56 +00:00
|
|
|
{ "manualcsv", "manualcsv2xml.xslt", NULL },
|
2015-02-17 17:16:21 +00:00
|
|
|
{ "logbook", "DiveLog.xslt", NULL },
|
2016-12-31 07:56:08 +00:00
|
|
|
{ "AV1", "av1.xslt", NULL },
|
2019-03-31 06:50:24 +00:00
|
|
|
{ "exportTrak", "Mares.xslt", NULL },
|
2014-02-16 23:42:56 +00:00
|
|
|
{ NULL, }
|
|
|
|
};
|
2011-11-16 05:12:43 +00:00
|
|
|
|
2020-10-17 18:15:23 +00:00
|
|
|
static xmlDoc *test_xslt_transforms(xmlDoc *doc, const struct xml_params *params)
|
2011-11-05 10:39:17 +00:00
|
|
|
{
|
2011-11-16 05:12:43 +00:00
|
|
|
struct xslt_files *info = xslt_files;
|
2011-11-05 10:39:17 +00:00
|
|
|
xmlDoc *transformed;
|
|
|
|
xsltStylesheetPtr xslt = NULL;
|
|
|
|
xmlNode *root_element = xmlDocGetRootElement(doc);
|
2023-05-19 01:40:40 +00:00
|
|
|
xmlChar *attribute;
|
2011-11-16 05:12:43 +00:00
|
|
|
|
2024-01-27 14:04:22 +00:00
|
|
|
if (!root_element)
|
|
|
|
return NULL;
|
|
|
|
|
2014-02-08 12:00:54 +00:00
|
|
|
while (info->root) {
|
2015-05-28 12:59:08 +00:00
|
|
|
if ((strcasecmp((const char *)root_element->name, info->root) == 0)) {
|
2014-02-08 12:00:54 +00:00
|
|
|
if (info->attribute == NULL)
|
|
|
|
break;
|
2023-05-09 03:03:27 +00:00
|
|
|
|
2023-05-19 01:40:40 +00:00
|
|
|
xmlChar *prop = xmlGetProp(root_element, (const xmlChar *)info->attribute);
|
2023-05-09 03:03:27 +00:00
|
|
|
if (prop != NULL) {
|
2023-05-19 01:40:40 +00:00
|
|
|
xmlFree(prop);
|
2023-05-09 03:03:27 +00:00
|
|
|
|
2014-02-08 12:00:54 +00:00
|
|
|
break;
|
2023-05-09 03:03:27 +00:00
|
|
|
}
|
2014-02-09 21:00:33 +00:00
|
|
|
}
|
2011-11-16 05:12:43 +00:00
|
|
|
info++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (info->root) {
|
2023-05-19 01:40:40 +00:00
|
|
|
attribute = xmlGetProp(xmlFirstElementChild(root_element), (const xmlChar *)"name");
|
2013-02-21 01:07:22 +00:00
|
|
|
if (attribute) {
|
2023-05-19 01:40:40 +00:00
|
|
|
if (strcasecmp((char *)attribute, "subsurface") == 0) {
|
|
|
|
xmlFree(attribute);
|
2013-02-21 01:07:22 +00:00
|
|
|
return doc;
|
|
|
|
}
|
2023-05-19 01:40:40 +00:00
|
|
|
xmlFree(attribute);
|
2013-02-21 01:07:22 +00:00
|
|
|
}
|
2011-11-16 05:12:43 +00:00
|
|
|
xslt = get_stylesheet(info->file);
|
2013-02-22 19:20:46 +00:00
|
|
|
if (xslt == NULL) {
|
2014-03-14 18:26:07 +00:00
|
|
|
report_error(translate("gettextFromC", "Can't open stylesheet %s"), info->file);
|
2011-11-05 10:39:17 +00:00
|
|
|
return doc;
|
2013-02-22 19:20:46 +00:00
|
|
|
}
|
2020-10-17 18:15:23 +00:00
|
|
|
transformed = xsltApplyStylesheet(xslt, doc, xml_params_get(params));
|
2011-11-05 10:39:17 +00:00
|
|
|
xmlFreeDoc(doc);
|
|
|
|
xsltFreeStylesheet(xslt);
|
2013-10-16 19:05:19 +00:00
|
|
|
|
2011-11-05 10:39:17 +00:00
|
|
|
return transformed;
|
|
|
|
}
|
|
|
|
return doc;
|
|
|
|
}
|