aboutsummaryrefslogtreecommitdiffstats
path: root/core/datatrak.c
AgeCommit message (Collapse)Author
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-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: unconditionally call freeGravatar Dirk Hohndel
While this is debatably correct, free will happily accept (and ignore the NULL pointer), so let's just always call it and make Coverity happy. Fixes CID 45163 Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2019-08-08Cleanup: move error reporting function declarations to errorhelper.hGravatar Berthold Stoeger
Move the declarations of the "report_error()" and "set_error_cb()" functions and the "verbose" variable to errorhelper.h. Thus, error-reporting translation units don't have to import the big dive.h header file. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-06-19Cleanup: move tag functions into own translation unitGravatar Berthold Stoeger
Make dive.h a bit slimmer. It's only a drop in the bucket - but at least when modifying tag functions not the *whole* application is rebuilt anymore. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-05-15Cleanup: small coding style fixesGravatar Dirk Hohndel
And addressing a cut and paste error in a comment. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2019-04-12Dive site: add dive site ref-countingGravatar Berthold Stoeger
Instead of setting dive->dive_site directly, call the add_dive_to_dive_site() and unregister_dive_from_dive_site() functions. In the parser this turned out to be a bit tricky. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-04-12Dive sites: prepare for dive site ref-countingGravatar Berthold Stoeger
Add a dive site table to each dive site to keep track of dives that have been added to a dive site. Add two functions to add dives to / remove dives from dive sites. Since dive sites now contain a dive table, the order of includes had to be changed: "divesite.h" now includes "dive.h" and not vice-versa. This caused some include churn. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-04-12Dive site: set UUID only on save or loadGravatar Berthold Stoeger
Since the UUID will be overwritten on save and is only used on save and load, set it only on save or load. For other created dive sites, leave the UUID field uninitialized. This means that the UUID will change between saves. Let's see how the git saver handles that. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
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-04-12Dive site: add dive site table parameter to dive site functionsGravatar Berthold Stoeger
To enable undo of dive site functions, it is crucial to work with different dive site tables. Therefore add a dive site table parameter to dive site functions. For now, always pass the global dive site table. Thus, this commit shouldn't alter any functionality. After this change, a simple search for dive_site_table reveals all places where the global dive site table is accessed. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-03-18Cleanup: remove bit field demux in datatrak.cGravatar Berthold Stoeger
To test single bits, datatrak.c would transform bytes into malloc()ed char[8] buffers. Instead, simply introduce a function to test individual bits. This should make it distinctly easier for the compiler to optimize away. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-03-18Cleanup: unglobalize variables in datatrak.cGravatar Berthold Stoeger
It's a drop in the bucket, but let's remove some unnecessary global variables. With one exception these variables were only used in one function anyway. The other one can be passed as a parameter. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-03-18Cleanup: remove unused global variables from datatrak.cGravatar Berthold Stoeger
lector_bytes and lector_word were used nowhere. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-03-17Core: remove variable name conflictGravatar Dirk Hohndel
Having a char parameter with the same name as a global char * variable is confusing. Found via LGTM.com Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2019-02-28Cleanup: make dt_dive_parser() local to datatrak.cGravatar Berthold Stoeger
The function is only used in this translation unit. 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-09Core: Rename functions to more generic namesGravatar Berthold Stoeger
Rename - dive_get_insertion_index() -> dive_table_get_insertion_index() - unregister_dive_from_table() -> remove_from_dive_table() - get_idx_in_table() -> get_idx_in_dive_table() - sort_table() -> sort_dive_table() This will make it more straight-forward to generate these functions from macros. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-29Dive site: replace dive->dive_site_uuid by dive_siteGravatar Berthold Stoeger
Replace the UUID reference of struct dive by a pointer to dive_site. This commit is rather large in lines, but nevertheless quite simple since most of the UUID->pointer work was done in previous commits. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-29Dive site: return pointer to dive_site in create_dive_site_*()Gravatar Berthold Stoeger
This changes more of the dive-site interface to return pointers instead of UUIDs. Currently, most call sites directly extract UUIDs afterwards. Ultimately, the UUIDs will be generally replaced by pointers, which will then simplify these callers. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-29Dive site: return pointer to dive_site in get_dive_site_*()Gravatar Berthold Stoeger
As a first step in removing dive-site uuids, change the interface of the get_dive_site_*() functions to return pointers instead of uuids. This makes code a bit more complicated in places where the uuid is extracted afterwards (needed NULL check). Nevertheless, these places should disappear once pointers instead of uuids are stored in the dive-structures. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-09-28Parser: parse text-based files into arbitrary tableGravatar Berthold Stoeger
In d815e0c9476ef62e6b84fb28ce48ab7cddefe77e a dive_table pointer was added to the parsing functions to allow parsing into tables other than the global dive table. This will be necessary for undo of import and implementation a cleaner interface. A few cases, notably CSV and proprietary formats were forgotten. Implement parsing into arbitrary tables also for these cases. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-05-14Core: remove dive.h from files that don't need itGravatar Dirk Hohndel
Of course, quite a few of them indirectly get it through other header files. Signed-off-by: Dirk Hohndel <dirk@hohndel.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-12-27Cleanup: avoid memory leakGravatar Dirk Hohndel
Coverity CID 45121 Coverity CID 45163 Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-12-26Cleanup: avoid memory leakGravatar Dirk Hohndel
The JUMP macro includes a 'goto bail', so we need to free devdata there Coverity CID 208340 Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-06-11datatrak.c: don't use POSIX %m format for sscanf() in dtrak_prepare_data()Gravatar Lubomir I. Ivanov
The format option "%m" doesn't work for MINGW/Windows and is reported as an unknown conversation type and this sscanf() call would not work. The alternative is to malloc() enough space manually - e.g. strlen(input) + 1. Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-05-27Fix some warningsGravatar Dirk Hohndel
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-05-07Datatrak import rework: main functionsGravatar Salvador Cuñat
datatrak_import() is the main function called from parse_file(), but dt_dive_parser() is where the hard work is done, for both, drop file seeking/reading and use memory pointers instead. datatrak_import() now returns 0 on success or 1 on failure and abort import if parser function fails instead of keeping on trying. dt_dive_parser() emits a warning if libdc_model is zero (manual dives). Do not parse profiles if libdc_model is zero, for unknown models we set a fake 0xEE value coverted to Aladin Air X/Z libdc model number. Func now takes a pointer to a buffer and moves along the dive, when done returns a pointer to the actual memory position or NULL if something went wrong. Signed-off-by: Salvador Cuñat <salvador.cunat@gmail.com>
2017-05-07Datatrak import rework: changes on helper funcsGravatar Salvador Cuñat
Remove dtrak_profile() profile parsing func as this work is left to libdivecomputer. Simplifies read_file_header() to return the number of dives in the log file as we don't use the rest of header data. Add dtrak_prepare_data() to achieve a device_data_t structure and get the correct libdc model number for the device. Remove checking macro substituted with JUMP in header file. Add dt_libdc_buffer() to get a buffer parseable with libdivecomputer. Signed-off-by: Salvador Cuñat <salvador.cunat@gmail.com>
2017-05-04Fix calculation of how many samples profile are in datatrack dive log fileGravatar Olivier Verstraet
2017-04-29Add SPDX header to core C filesGravatar Dirk Hohndel
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-03-12Only enable -Wmissing-field-initializers for ClangGravatar Lubomir I. Ivanov
The following pragma is Clang specific: It produces a warning: warning: ignoring #pragma clang diagnostic [-Wunknown-pragmas] Only enable it for Clang by checking the __clang__ macro. Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-03-11Merge branch 'master' of https://github.com/dje29/subsurfaceGravatar Dirk Hohndel
2017-03-11divelog > dive logGravatar Martin Měřinský
2017-03-09Fix potential double/float to int rounding errorsGravatar Jeremie Guichard
Not using lrint(f) when converting double/float to int creates rounding errors. This error was detected by TestParse::testParseDM4 failure on Windows. It was creating rounding inconsistencies on Linux too, see change in TestDiveDM4.xml. Enable -Wfloat-conversion for gcc version greater than 4.9.0 Signed-off-by: Jeremie Guichard <djebrest@gmail.com>
2017-03-04Consistent 'salt water' versus 'fresh water'.Gravatar Martin Měřinský
2017-02-21Translate names of additional dive events and nicer format info box textGravatar Stefan Fuchs
Enable translation for a few additional internal dive events. Ensure that all event names in datatrak.c are collected for translation. Ensure that for gaschange in profile info box the "cyl." string is also translated. Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2016-04-04Move subsurface-core to core and qt-mobile to mobile-widgetsGravatar Dirk Hohndel
Having subsurface-core as a directory name really messes with autocomplete and is obviously redundant. Simmilarly, qt-mobile caused an autocomplete conflict and also was inconsistent with the desktop-widget name for the directory containing the "other" UI. And while cleaning up the resulting change in the path name for include files, I decided to clean up those even more to make them consistent overall. This could have been handled in more commits, but since this requires a make clean before the build, it seemed more sensible to do it all in one. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>