Basically, this alows us to hide the usbhid code behind the custom_io
abstraction, so that a dive computer could either be given a supplied
custom_io structure, of if none is given, would create one for a USBHID
device.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
The custom IO handlers will be extended to not just do serial line
emulation (generally over Bluetooth rfcomm), but do BLE too.
BLE does not look like a serial protocol at all, it's packet-based, and
we may have to add specific routines to indicate which GATT endpoints to
use etc. But like the traditional custom serial code, we want to do the
actual IO not from within libdivecomputer, but from the user of the
library (because the BLE support will require things like the Qt
Connectivity layer - and we do not want libdivecomputer to have to link
against something like Qt).
So this renames 'custom_serial' to 'custom_io', and instead names the
individual member function pointers 'serial_*' to make it clear that
those members are for serial communication.
It also adds new placeholders for packet_open/close/read/write. Note
that while these may look similar to the serial counter-parts, they are
not the same or even necessarily mutually exclusive. It is possible the
the caller fills in one or the other (or both), and they would be used
independently.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Not that anybody should ever use that old-style family/model thing
anyway, so I considered just removing the g2 entry instead. But dctool
still uses this deprecated interfsce to pick a dive computer.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
I did the packet logging for the received data side, but forgot to do
the same thing on the command transfer side, which makes the debug logs
a bit less useful.
Of course, it turns out that a bug in subsurface means that the logging
never gets enabled anyway even when you ask for it, so right now this
particular misfeature didn't matter. I'm hoping Tomaz/Dirk can fix the
UI widget problem.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
When doing the G2 downloader, I dropped the initial handshake as I tried
to keep the code minimal, and the handshake didn't seem to make any
difference what-so-ever to me.
And it probably doesn't matter for anybody else either. But the code
isn't working for some people, and maybe it does actually matter.
More importantly, Scubapro's own LogTRAK application does send those two
initial commands, and it's probably a good idea to minimize the
differences between the different downloaders anyway, so add the
handshake sequence back in.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Jef Driesen correctly points out that the 'address' field is just
leftover from the IrDA code, and is meaningless for the USB HID
transport version of the Scubapro G2.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
The back-end parser seems to be the same as for the Uwatec Smart (aka
Galileo Sol). At least that's the assumption right now.
The downloader just uses USB HID (very similar to EON Steel) rather than
the horrible IrDA thing.
There's also eventually a BLE thing, but that's for the future.
This is an unholy mixture of the Uwatec Smart downloader logic and the
EON Steel usbhid transfer code. The back-end is pure Uwatec Smart
(model 0x11, same as Galileo Sol).
I'm not at all sure this gets everything right, but it downloads
*something*.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Merge upstream libdivecomputer changes as requested by Jan Mulder.
"DiveSystem iX3M:
- Add support for new iX3M models
- Add support for new iX3M APOS4 firmware
- Add iX3M firmware version to the devinfo event (ix3m)
Shearwater:
- Report the ppO2 in external O2 sensor mode only (Shearwater)
- Replace the constant offset with a scaling factor (Shearwater)
- Apply the calibration correction only for the Predator
- Report individual sensor values
- Predator: don't report PPO2 unless in CC mode
Misc:
- Fix Sherwood Wisdom 3 memory layout
- Implement read and write functions for OSTC3
- Add support for Mares Quad
- Fix uwatec handshaking error handling"
* 'master' of git://git.libdivecomputer.org/libdivecomputer:
Add support for the new models
Add support for the new iX3M APOS4 firmware
Add the firmware version to the devinfo event
Report the ppO2 in external O2 sensor mode only
Replace the constant offset with a scaling factor
Apply the calibration correction only for the Predator
shearwater: Report individual sensor values
Predator: don't report PPO2 unless in CC mode
Fix the Sherwood Wisdom 3 memory layout
Implement the read and write functions for the OSTC3
Don't ignore handshaking errors
Add support for the Mares Quad
The new APOS4 firmware changed the data format and communication
protocol. The size of the samples changed from 54 to 64 bytes, and in
order to speedup the download, a single data packet contains 3 samples
at once. If the number of samples is not an exact multiple of three, the
last packet appears to contain garbage data.
For parsing, the firmware version is available in the dive header.
Unfortunately it can't be used for dives that are downloaded from a
device with the new firmware, but which have been recorded with an older
firmware. Such dives store the old firmware version in the dive header,
but they also use the new sample format. As a workaround, we inspect the
size of the dive.
The O2 sensor millivolt values are only valid if external O2 sensor
monitoring is enabled.
Note that the interpretation of the PPO2 status bit appears to be
reversed (0=external and 1=internal).
Reviewed-by: Anton Lundin <glance@acc.umu.se>
Correcting the Predator calibration value with a scaling factor produces
even more reasonable ppO2 values compared to using a constant offset.
The scaling factor of 2.2 is based on a linear regression between the
average ppO2 reported by the dive computer, and the average ppO2
calculated over all (calibrated) sensors using the raw calibration
value.
Reviewed-by: Anton Lundin <glance@acc.umu.se>
The calibration values for the Petrel are typically in the range 1600 to
2400, while for Predator they are much smaller, with values in the range
800 to 1400. The consequence is that the calculated ppO2 values are too
low for the Predator. Adding a constant offset of about 1000 changes the
calibration value to be in approximately the same range as the Petrel,
and hence more reasonable ppO2 values. But this correction should only
be applied for the Predator, and not the Petrel.
Reviewed-by: Anton Lundin <glance@acc.umu.se>
This reads the reported mV values from the sensors, and based on the
calibration values converts it into a ppo2 value to report.
Signed-off-by: Anton Lundin <glance@acc.umu.se>
Sending this in OC mode is redundant and might confuse applications that
assume they only get PPO2 data in CC mode.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
From firmware version 2.15, the battery percentage is shown on the
unit (in the logbook that is, it was shown on the display for a very
long time). The used byte in the OSTC3 seems to be populated since
firmware version 2.10. The new percentage data is added to the
"battery at end" voltage data, and a V is added to denote the unit
of the voltage.
In addition, reordered the DC_FIELD_STRINGs a little, so that the
serial is on top.
Further, changed BUFLEN to 32 (as in 84eb59c) due the the length
of the new battery notation.
Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
Merge upstream libdivecomputer changes from Jef Driesen.
The most noticeable part is Jen Mulder's OSTC3 initial setpoint
addition, which fixes the OSTC3 data in CCR3 mode.
But also various cleanups and fixups from Jef.
* 'master' of git://git.libdivecomputer.org/libdivecomputer:
OSTC3: set initial setpoint in profile data
Remove unused parameters
Cleanup the extract dives functions
Remove unnecessary helper functions
Remove deprecated functions from the public api
Remove unnecessary include statements
Fix the firmware version and serial number
Add support for the Uwatec Aladin Tec 3G
In CCR fixed setpoint mode of the OSTC3, the initial setpoint at the start
of the dive was not set. This fix adds the initial setpoint based on
the data in the fixed setpoint table (ie, the first fixed setpoint is
the initial one).
Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
After being removed from the public api, these functions can be changed
into local, static functions. And in a few cases, they are no longer
necessary and can be removed completely.
The second variant of the open or create functions were introduced to
maintain backwards compatibility. But after being removed from the
public api, these functions serve no purpose anymore, and can be removed
completely.
The vendor_product_parser_create() and vendor_product_device_open()
functions should be called indirectly, through the generic
dc_device_open() and dc_parser_new() functions. And the
vendor_product_extract_dives() functions are internal functions that
should never have been part of the public api in the first place.
Merge upstream libdivecomputer changes from Jef Driesen.
No major changes and no conflicts except for a trivial one where Jef had
marked a couple of private functions 'static' and our versions had
extended the argument lists of those functions.
This just updates to the current upstream state of libdivecomputer,
where the bulk of the changes come mainly from the new ringbuffer helper
code, but there are various other small misc fixes and cleanups.
* git://git.libdivecomputer.org/libdivecomputer:
Disable the deco events
Replace the deco events with a deco sample
Report errors from the close function
Mark the private function as static
Fix a bug in the tank pressure samples
Disable freedive mode for the Uwatec Aladin Tec 2G
Mark the private function as static
Fix some compiler warnings
Fix some more null pointer dereferences
Use a more efficient download algorithm
Use the new ringbuffer stream
Add a common ringbuffer reading algorithm
Improve the robustness of the IrDA I/O code
Fix a few null pointer dereferences
Fix the number of gas mixes
Always use the sample timestamp as the base value
When compiled with older Microsoft libraries, the unsafe implemention of
snprintf results in non-null terminated strings, causing numerous subsequent
issues. This fix just enlarges the used buffer to accommdate longer strings.
A more complete solution would include the use more recent Microsoft libraries in
the build process. The larger buffer is still need then, to prevent trucated
(but proper null terminated) strings.
ref: https://github.com/Subsurface-divelog/subsurface/issues/301
Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
When downloading a Shearwater Petrel using the predator backend, the
firmware version and serial number are different compared to those
reported by the petrel backend.
This is caused by a difference in the encoding of the data. In the
predator data format, the firmware version appears to be BCD encoded,
and the serial number is stored as a big endian integer.
The number of tank pressure sensors is not necessary equal to the number
of gas mixes. Take for example a dive with two gas mixes, but only a
single tank pressure sensor attached to one of the two tanks. Because
the tank index is shared with the gas mix index, it will refer to a
non-existing sensor when switching to a tank without a pressure sensor
attached.
The invalid tank index should not be considered a fatal error. The tank
pressure values should be ignored instead. The device appears to record
zero values anyway, except for the first value immediately after the gas
switch. I suspect that's caused by the fact that the pressure is only
recorded every 4 samples, and therefore the last pressure value is
reported with a small delay.
The Uwatec Aladin Tec 2G doesn't support freedive mode. This appears to
be a bug in SmartTrak and LogTrak. They both report gauge and air/nitrox
dives as apnea dives.
The current algorithm always downloads a full memory dump, and extracts
the dives afterwards. For the typical scenario where only a few dives
are being downloaded, this is inefficient because most of the data isn't
needed. This can easily be avoided by downloading the data on the fly.
Reading a ringbuffer backwards in order to process the most recent data
first, is a very common operation. Nearly every dive computer backend
has its own implementation. Thus with a common implementation, the
amount of code duplication and complexity in the dive computer backends
can be greatly reduced.
The common algorithm is implemented as a simple ringbuffer stream, which
takes care of all the technical details like the ringbuffer boundaries,
alignment to the page size, using the optimal packet size and caching
the remaining data.
The select system call modifies the file descriptor set, and depending
on the underlying implementation also the timeout. Therefore these
parameters should be re-initialized before every call.
The existing code also didn't handle EINTR and EAGAIN correct.