summaryrefslogtreecommitdiffstats
path: root/libdivecomputer.c
AgeCommit message (Collapse)Author
2015-12-06Only warn about different number of tanks and gases if there are tanksGravatar Dirk Hohndel
Some backends support giving tank data for some, but not all models that they support (and simply report no tanks for those models that don't support this). The Suunto Vyper is one of the dive computers where this happens and without this change we report angry red warnings after a perfectly correct download. So this changes the logic to only show that error if there actually were tanks reported. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-12-06Don't overwrite air temperatureGravatar Dirk Hohndel
If we already have an air temperature set, don't overwrite it with potentially less accurate infromation from the first sample. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-10-26Fix building without BT supportGravatar Dirk Hohndel
I guess no one had tried this in a while. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-10-25Interpolate depth for samples that have no depthGravatar Linus Torvalds
When downloading from libdivecomputer, we used to initialize the depth of a sample to the previous depth. However, at least for the Suunto EON Steel, you can get sample times without any actual depth reading - the time might be associated with some ranbdom event rather than a new depth sample. Rather than initialize these samples to have the same depth as the previous one (and then perhaps getting a very sudden jump when the *real* depth event comes in a second later), initialize the depth samples to -1, and if that sample doesn't get a real depth, we'll create an interpolated depth. It is possible that we should just carry the sample around as not actually having a depth, and instead just interpolate in the plot_info generation, but at least right now we have a ton of code that "knows" that every sample has a depth. Not the least of which is our own save format. So generating an interpolated depth seems the path of least resistance, and at least makes the graph look correct - no odd staircase effect from other events that happen in between depth samples. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-10-22Interpretive dance to parse Suunto EON Steel tank sizesGravatar Dirk Hohndel
Admittedly, imperial tank sizes are a bit weird. But it must have taken some effort to break things as creatievly as Suunto did. The UI allows only multiples of 100psi and multiples of 10cuft. Which shows that the developers have no idea what typical imperial tanks look like. AL72? AL63? HP tanks at 3440psi? LP+ at 2640psi? Yeah, I get it - you had no idea, someone showed you an AL80 and you made silly assumptions. But even then, what the heck are you storing in your data, dear Suunto? The pressures are off by the very logical factor of 1.00069182389937. And then regardless whether I use the wrong pressure or the corrected pressure, the wet sizes are too small by a non-constant factor. So this code takes the junk that libdivecomputer truthfully passes through from the Suunto parser and tries to convert it into something that matches what the user most likely entered in the EON Steel UI. Ugly. Stupid. But it seems to work. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-09-23libdivecomputer.c: fix warnings about unused variablesGravatar Lubomir I. Ivanov
Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-09-13Store the number of detected o2 sensorsGravatar Anton Lundin
To make our logic to handle o2 sensors do usefull things we need to inform it of the amout of o2 sensors we got. This saves the max number of PPO2 samples we got from libdivecomputer as our number of o2 sensors. Signed-off-by: Anton Lundin <glance@acc.umu.se> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-09-13Remove leftover bits between sensors and setpointGravatar Anton Lundin
Previously subsurface treated DC_SAMPLE_SETPOINT and DC_SAMPLE_PPO2 the same way. Back in "Store DC_SAMPLE_PPO2 as a o2 sensor", and "Support multiple o2 sensor values from libdc", i changed that and started to treat DC_SAMPLE_PPO2 as the o2 sensor values they are. The po2 variable there was a leftover from when ppo2 and setpoints where treated the same way, and should be removed. Signed-off-by: Anton Lundin <glance@acc.umu.se> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-09-09Exit with failure if the first dc_open method failsGravatar Claudiu Olteanu
If the dc_serial_*_open method fails then we should exit with an error and don't try to open the device using the native implementation. Signed-off-by: Claudiu Olteanu <olteanu.claudiu@ymail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-08-31Support multiple o2 sensor values from libdcGravatar Anton Lundin
libdivecomputer might call us with DC_SAMPLE_PPO2 multiple times, which means multiple sensors. Signed-off-by: Anton Lundin <glance@acc.umu.se> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-08-31Store DC_SAMPLE_PPO2 as a o2 sensorGravatar Anton Lundin
DC_SAMPLE_PPO2 represents a known ppO2, and not a setpoint. Signed-off-by: Anton Lundin <glance@acc.umu.se> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-08-20Connect up serial_ftdi custom serialGravatar Anton Lundin
This connects the serial_ftdi implementation to subsurface, and builds libftdi1 for the android builds. Signed-off-by: Anton Lundin <glance@acc.umu.se> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-07-30Add support for RBT reported sample valueGravatar Salvador Cuñat
RBT (Remaining Bottom Time) is a value calculated on the fly by some air integrated divecomputers, for example Uwatec devices. This value is an estimation based in some heuristic around time function pressure gradients. This way, RBT would be the time a diver can spend at actual depth without running out of gas (taking account of ascent, deco, if required, and rock bottom gas reserve, if set). Older Uwatec devices just made the calculus and only stored alarm events if this time value reached zero, but modern devices store the value each sample, in minutes. It seems that Suunto Eon Steel is storing RBT values too, in seconds. Libdivecomputer has supported RBT for a while, but Subsurface just printed it to stdout and dropped it. This adds support for RBT value on subsurface sample structure and shows it in the profile's info box, right under TTS(calc), if selected, where these two values can be easily compared by humans. Signed-off-by: Salvador Cuñat <salvador.cunat@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-07-07Allow to compile Subsurface with upstream libdivecomputerGravatar Dirk Hohndel
This will create an inconsistent build that has some UI features implying BT support but those will be non-functional. I don't think this is the right thing to do - either fail to build with a decent message or really remove the BT support. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-07-06Implement the custom Bluetooth serial communication and use itGravatar Claudiu Olteanu
Create a custom Bluetooth serial communication using the QTBluetooth API and use it when the Bluetooth download mode is enabled. First try to connect on RFCOMM channel 1 because this is the default RFCOMM channel of SPP service for most devices. If this doesn't work try again on RFCOMM channel number 5 because it could be a Petrel2 device. Add a fake open function for the custom implementation. This is used when the selected device is HW OSTC 2N and the Bluetooth mode is activated, then fake the open call of the serial device. Signed-off-by: Claudiu Olteanu <olteanu.claudiu@ymail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-07-02Use tank pressure data from libdivecomputer's DC_FIELD_TANKGravatar Dirk Hohndel
When libdivecomputer switched to the DC_FIELD_TANK API it apparently stopped creating fake pressure samples at the start and end of a dive for dive computers that don't have continuous pressure reporting but that instead only report those two values. This updates our code to take those values into account. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-06-21Fix a number of resource leaksGravatar Dirk Hohndel
Free memory returned from parse_mkvi_value() Free memory returned from printGPSCoords() Free memory allocated in added_list and removed_list Free memory allocated when adding suffix to dive site name Free memory allocated in cache_deco_state() Free memory allocated in build_filename() Free memory allocated in get_utf8() Free memory allocated in alloc_dive() Free memory allocated as cache but never used Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-05-28Add explicit casts to silence compiler warningsGravatar Robert C. Helling
clang complais when converting (char *) to (unsigned char *), so tell it it's fine. Signed-off-by: Robert C. Helling <helling@atdotde.de> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-05-27Enable diagnostic logs from dc configurationGravatar Anton Lundin
This implements support for writing debug/diagnostic logs when configuring dive computers and upgrading the firmware. Signed-off-by: Anton Lundin <glance@acc.umu.se> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-04-29Add a default case for switch over dc_family_tGravatar Anton Lundin
This adds a default case which just errors out for the switch over dc_family_t instead of checking a uninitialized variable if this was ever called with something else than one of the expected dc-family types. Signed-off-by: Anton Lundin <glance@acc.umu.se> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-04-04libdivecomputer.c: Remove unused parameter in parse_gasmixesGravatar Salvador Cuñat
data pointer is not used, so it can be safely removed. Signed-off-by: Salvador Cuñat <salvador.cunat@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-04-04libdivecomputer.c: Add support for raw data buffer parse using libdcGravatar Salvador Cuñat
Add function libdc_buffer_parser() intended to parse raw data buffers prepared for libdivecomputer. We have to commit elsewhere the necesary assembly tasks to achieve consistent data. Actually only OSTCTools import makes use of this feature. Uwatec families have been included as I expect to make use of this function for sample parsing in datatrak import (and, may be in a far future, smartrak). Signed-off-by: Salvador Cuñat <salvador.cunat@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-04-04libdivecomputer.c: Split dive_cb() callback in twoGravatar Salvador Cuñat
dive_cb() needs a defined device to work as it's built for DC download tasks. Move part of the functionality of dive_cb() to a new function libdc_header_parser() which can be used to parse headers from raw data buffers with no device set. Obviously dive_cb() will call the new funtion for header parsing too. Two changes in logic: 1- In parse_gasmixes() set data pointer to NULL. This pointer is passed to the function, but it's not used. While this data pointer exists in DC import, via dive_cb(), it doesn't in file import as data has previously been set in the parser. 2- While parsing gas mixes do not return on rc = DC_STATUS_UNSUPORTED because it would end our dive parsing just if the device doesn't support gases, which seems undesirable in both, DC or file import. Signed-off-by: Salvador Cuñat <salvador.cunat@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-04-04Add errmsg() function for libdivecomputer.cGravatar Salvador Cuñat
Taken as is from libdivecomputer exaples/common.c to improve verbosity on libdc return codes. Intended to be used on error messages shown to the user on main window complementarily to those messages managed by dev_info(). Signed-off-by: Salvador Cuñat <salvador.cunat@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-03-19Fix a couple of typosGravatar Torstein Husebø
Signed-off-by: Torstein Husebø <torstein@huseboe.net> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-02-09Prevent a tank from looking undefined by mistakeGravatar Dirk Hohndel
If we have no default cylidner set and get no data about an air tank from libdivecomputer, our cylinder will look completely empty by mistake. Always setting some kind of description fixes that. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-01-22Set divemode to FREEDIVE now when we support thatGravatar Anton Lundin
Previous code mapped all our free dive inputs to OC, but now when we actually have a FREEDIVE divemode, we can do better. Signed-off-by: Anton Lundin <glance@acc.umu.se> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-01-19Remove the two annoying debug statementsGravatar Dirk Hohndel
These should have been removed ages ago... Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-01-10Refactor dctype -> divemodeGravatar Robert C. Helling
... and repair a failed rebase (sorry). Signed-off-by: Robert C. Helling <helling@atdotde.de> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-01-09Now use our table when downloading from the dive computerGravatar Dirk Hohndel
We pass a different table to libdivecomputer (and the uemis code) and have that table filled. And then we simply copy the dives from that table into the real dive_table when the user accepts the download. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-01-09Don't use the result of unsupported libdivecomputer callsGravatar Dirk Hohndel
We report a bug if this is not unsupported and not successful. And then use the result. Hello? So if this is not supported, we still use the result? Oops. This has been around for a long time. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-12-29Remove unused variableGravatar Anton Lundin
Signed-off-by: Anton Lundin <glance@acc.umu.se> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-12-29Clear stale pointers after freeGravatar Anton Lundin
This is so that we can re-use the same device_data_t in other calls that doesn't allocate a context for example. Signed-off-by: Anton Lundin <glance@acc.umu.se> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-12-27Keep undecoded firmware / serial info from libdivecomputerGravatar Dirk Hohndel
This needs to become a string in libdivecomputer - but for now let's just keep the integers so we can parse it elsewhere when we know which model it is - the generic parsing into a string is completely bogus and needs to go. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-12-01libdivecomputer.c: reduce the scope of 'i' in sample_cb()Gravatar Lubomir I. Ivanov
Silences a warning about an unused variable. Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-11-25Consistent representation of O₂Gravatar Tim Wootton
Signed-off-by: Tim Wootton <tim@tee-jay.demon.co.uk> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-11-24Let's not store more or less random dataGravatar Dirk Hohndel
The backend needs to convert the firmware and serial information into a sane string - Subsurface shouldn't try to do this by itself. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-11-21Add serial and firmware to the extra dataGravatar Dirk Hohndel
And add the missing newline to the debug output to help us identify encodings for serial and firmware. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-11-20Remember serial and firmware for divecomputersGravatar Dirk Hohndel
This is not the right way to get serial numbers and firmware versions. The libdivecomputer interface here is simply broken. Those ARE NOT numbers. But until we have the capability in libdivecomputer to return reasonable strings to us, this could be a stop gap measure to help us understand how these are formatted. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-11-20Stop cluttering stout with DC_VENDOR dataGravatar Dirk Hohndel
This was intended for debugging and somehow stayed enabled. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-11-13Add subsurface_access()Gravatar Lubomir I. Ivanov
For our usage the method will acept UTF-8 paths, which are converted to UTF-16 on Win32. Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-11-12Shows an error about wrong permissionsGravatar Salvo 'LtWorf' Tomaselli
If an import fails, the permissions of the device are tested and an error message that mentions permissions is shown to the user. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-11-11Remove leftover code for directly parsing Cobalt tank sizesGravatar Dirk Hohndel
This should have been ripped out as part of commit 4be760463422 ("Use libdivecomputer tank size when available"). Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-11-11Fix getting tank information from libdivecomputerGravatar Dirk Hohndel
Silly type made us always get tank 0. So tanks 1 through n where wrong (and repeating tank 0 instead). Reported-by: Jef Driesen <jef@libdivecomputer.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-11-08Fix previous commit to compile with older versions of libdivecomputerGravatar Dirk Hohndel
That was silly :-( Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-11-08Use libdivecomputer tank size when availableGravatar Dirk Hohndel
If the gasmix of a tank is not the matching gasmix in the list of gasmixes, issue a warning (as so far we assume those are always in sync). This patch removes our own parsing of the sizes because Subsurface 4.3 will require libdivecomputer 0.5 so this should be enabled by the time the next release comes out, so let's just drop the redundant code. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-11-08Add support for libdivecomputer DC_FIELD_DIVEMODEGravatar Anton Lundin
libdivecomputer recently gained a api for telling us which mode the divecomputer was running in, so this uses that to tell us if it was a OC or CCR dive. Signed-off-by: Anton Lundin <glance@acc.umu.se> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-11-08Move calculate_string_hash into DC_FIELD_STRINGGravatar Anton Lundin
The calculate_string_hash is only used if DC_FIELD_STRING is defined, so this removes a warning for everybody who doesn't build against a libdivecomputer with DC_FIELD_STRING support. Signed-off-by: Anton Lundin <glance@acc.umu.se> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-11-07Add support for libdivecomputer's new TEMPERATURE fieldsGravatar Dirk Hohndel
Parse air temperature and water temperature if available from the dive computer. Subsurface happily tracks the temperatures in the dive samples, but for water temperature in the header ("overall" water temperature) we currently support only one field. So I ordered the code so that if it is available, the minimum water temperature will be used, absent a minimum water temperature we use the maximum water temperature. Side note: Since the libdivecomputer maintainer disagrees with the Subsurface developers regarding a sane way to allow a consumer of his library to detect if a feature is supported in a particular commit of the library, the way we decide whether to build this code or not is decidedly hacky. DC_GASMIX_UNKNOWN happens to be a #define we can check that was added right around the time the temperature support was added. Sadly there is no #define that we could check to see if temperature fields are supported. How insane is that... Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-11-07Use the new DC_FIELD_STRING callback if it existsGravatar Linus Torvalds
This recognizes recognize some strigns (serial number and firmware version), and the ones that it doesn't recognize it adds as extra data using Dirk's new interface. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>