summaryrefslogtreecommitdiffstats
path: root/core/import-shearwater.c
AgeCommit message (Collapse)Author
2020-10-25cleanup: remove system includes from dive.cGravatar Berthold Stoeger
Let the various source files include the system headers they need themselves. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-25cleanup: split out divecomputer functions from dive.cGravatar Berthold Stoeger
Since dive.c is so huge, split out divecomputer-related functions into divecomputer.[c|h], sample.[c|h] and extradata.[c|h]. This does not give huge compile time improvements, since struct dive contains a struct divecomputer and therefore dive.h has to include divecomputer.h. However, it make things distinctly more clear. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-24parser: add device_table to parser stateGravatar Berthold Stoeger
If we want to avoid the parsers to directly modify global data, we have to provide a device_table to parse into. This adds such a state and the corresponding function parameters. However, for now this is unused. Adding new parameters is very painful and this commit shows that we urgently need a "struct divelog" collecting all those tables! Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-16Duration is in secondsGravatar Miika Turkia
The dive duration is given in seconds in the Shearwater cloud database. (At least nowadays.) Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
2020-09-19Update Shearwater sample time calculationGravatar Miika Turkia
At least Shearwater Cloud seems to use multiple formats for sample time recorded in the database. Sometimes the time is in seconds, sometimes in milliseconds, and sometime it is something I have no idea about. Thus switching to calculating the sample id myself and using sample interval to calculate the actual sample time. Seems to be more reliable than trying to guess what format Shearwater is using for this specific dive. Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
2020-09-15Grab the first gas on Shearwater importGravatar Miika Turkia
The logic to retrieve gas changes from Shearwater cloud database is detecting only when the O2/He chnages. This change will grab the initial gas. (Problem was only shown when there was a gas changee in the log, so cingle cylinder dives were working fine.) Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
2020-09-15Fix a bug on Shearwater cloud gas changesGravatar Miika Turkia
Gas change is done to the cylinder we just found and not the last cylinder. Also switching the variable name to index as we are actually using that value outside the loop. Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
2020-09-15Import cylinder pressure correctlyGravatar Miika Turkia
Shearwater apparently stores correct pressures nowadays, so getting rid of a hack to import double pressures. Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
2020-09-15Ignore gas changes if we one line contains bogus O2Gravatar Miika Turkia
This will ignore the gas changes that would be caused by Shearwater cloud saving rows with 0 values in them. Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
2020-09-15New field for timestamp in shearwater cloud DBGravatar Miika Turkia
Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
2020-09-15Shearwater cloud import: ignore bogus rowsGravatar Miika Turkia
A sample log I received contains a lot of rows with 0 values in it. This will ignore the obviously bogus ones. (However, we might miss the first sample if that is recorded at time 0.) Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
2019-11-09Cylinders: access cylinders with get_cylinder()Gravatar Berthold Stoeger
Instead of accessing the cylinder table directly, use the get_cylinder() function. This gives less unwieldy expressions. But more importantly, the function does bound checking. This is crucial for now as the code hasn't be properly audited since the change to arbitrarily sized cylinder tables. Accesses of invalid cylinder indexes may lead to silent data-corruption that is sometimes not even noticed by valgrind. Returning NULL instead of an invalid pointer will make debugging much easier. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-11-09Cleanup: return cylinder from cylinder_start() in parserGravatar Berthold Stoeger
Most callers of this function accessed the newly generated cylinder immediately after calling this function. Thus, for convenience, return the added cylinder. This avoids a number of verbose expressions. On the flip side, cylinder_start() now has to be cast to function returning void in a the "nesting" function table. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-11-09Core: remove MAX_CYLINDERS restrictionGravatar Berthold Stoeger
Instead of using fixed size arrays, use a new cylinder_table structure. The code copies the weightsystem code, but is significantly more complex because cylinders are such an integral part of the core. Two functions to access the cylinders were added: get_cylinder() and get_or_create_cylinder() The former does a simple array access and supposes that the cylinder exists. The latter is used by the parser(s) and if a cylinder with the given id does not exist, cylinders up to that id are generated. One point will make C programmers cringe: the cylinder structure is passed by value. This is due to the way the table-macros work. A refactoring of the table macros is planned. It has to be noted that the size of a cylinder_t is 64 bytes, i.e. 8 long words on a 64-bit architecture, so passing on the stack is probably not even significantly slower than passing as reference. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-10-26Cleanup: pass NULL pointer for error string pointerGravatar Dirk Hohndel
Since we never did anything with the error string, why even ask for it. And this way we don't have to deal with the memory returned, either. Found by Coverity. Fixes CIDs 350124, 350113, 350106, 350099, 350091 Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2019-04-12Parser: parse into custom dive site tableGravatar Berthold Stoeger
To extend the undo system to dive sites, the importers and downloaders must not parse directly into the global dive site table. Instead, pass a dive_site_table argument to parse into. For now, always pass the global dive_site_table so that this commit should not cause any functional change. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-01-09Parser: add trip_table parameter to parsing functionsGravatar Berthold Stoeger
To allow parsing into arbitrary trip_tables, add the corresponding parameter to the parsing functions and the parser state. Currently, all callers pass the global trip_table so there should be no change in functionality. These arguments will be replaced in subsequent commits. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-01-03Use state structure for sample rate infoGravatar Miika Turkia
Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
2019-01-01Use correct value for PO2Gravatar Miika Turkia
averagePPO2 appears to be correct value instead of currentPPO2SetPoint. Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
2018-12-31Grab correct setpoint on Shearwater cloud importGravatar Miika Turkia
Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
2018-12-30Use different time field as it seems to be more correctGravatar Miika Turkia
The starTimestamp is 4 hours apart on 2 different DCs within the sample log. DiveDate on the dive_logs table seems to be correct, but must be converted from human readable format. Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
2018-12-29Sample rate varies between divesGravatar Miika Turkia
Seems that Shearwater cloud stores sample rate into the database and it is not constant within the log. Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
2018-12-29Initial support for Shearwater CloudGravatar Miika Turkia
This works to some extent to part of a sample log I received. However, still quite a bit more work is needed. Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
2018-12-29Shearwater import: dive id might be large than intGravatar Miika Turkia
I encountered this while implementing Shearwater Cloud import, but it makes sense to increase the size for dive id for Shearwater Desktop as well. Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
2018-10-23Parser: make parser (mostly) reentrantGravatar Berthold Stoeger
Introduce a parser_state structure, which describes (most) of the global parser state. Create such a structure in the entry routines to the parser and pass it down to the individual functions. The parser state is initialized and freed with the init_parser_state() and free_parser_state() functions. The main benefits are: 1) Isolation of parser state. 2) Keeping the global name space tidy. 3) Prevent memory leaks which could happen in truncated files by freeing all the parser state after parse. A somewhat controversial point might be that the individual parsing functions are split in those that need parser-state and those that don't. This means that there are now two versions of the MATCH macro, viz. one for the former and one for the latter. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-05-27Remove unnecessary {}Gravatar Miika Turkia
Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
2018-05-27Shearwater import: avoid running atoi multiple timesGravatar Miika Turkia
Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
2018-05-27Shearwater import: support for DC reported ceilingGravatar Miika Turkia
This adds support for DC reported ceiling when importing the Shearwater Desktop database. Both AI and non-AI versions are tested, but not all possible paths. For non-AI the DC reported ceiling was from firstStopDepth and for the AI version it was from the decoCeiling field. I do not currently know when each of these fields are used, but at least this works on my test data. Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
2018-05-24core: replace (void) with UNUSED(x) and include ssrf.hGravatar jan Iversen
Unused parameters in C are "silenced" by adding UNUSED(x) Signed-off-by: Jan Iversen <jani@apache.org>
2018-05-14Core: introduce new subsurface-string headerGravatar Dirk Hohndel
First small step to shrinking dive.h. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-11-29Move Shearwater DB import into its own fileGravatar Miika Turkia
Signed-off-by: Miika Turkia <miika.turkia@gmail.com>