1043 Commits

Author SHA1 Message Date
Jef Driesen
d5eaa979d0 Convert the CNS value to a percentage. 2015-05-12 19:54:15 +02:00
Jef Driesen
4094f379ae Merge branch 'suunto' 2015-05-08 08:29:13 +02:00
Jef Driesen
106abe2dba Remove the temperature and pressure samples.
With the new temperature and pressure field, artificially injecting the
temperature and pressure info from the header into the samples is no
longer necessary. Applications will typically expect a real temperature
or pressure profile, and not a few discrete points.

The two surface samples (with zero depth) at the begin and end of the
dive are kept for now, to support events that occur at the surface.
2015-05-08 08:17:18 +02:00
Jef Driesen
7278a70afe Implement the tank and temperature fields. 2015-05-08 08:15:09 +02:00
Jef Driesen
5a61ffcc2f Use a variable for gauge mode.
This makes the code a little bit more readable, without needing any
comments.
2015-05-08 08:14:06 +02:00
Jef Driesen
e1f939c131 Move all caching code to a common function. 2015-05-05 21:15:51 +02:00
Jef Driesen
02e812f88b Apply the ghost event fix for the Suunto Solution.
I forgot to include the Suunto Solution part in the previous commit.

In theory the Suunto Solution (and Eon) can't be affected by the ghost
event bug. All possible events bytes are already exhausted, and
therefore unknown events are impossible. But applying the fix anyway
doesn't hurt and keeps the code consistent with the other backends.
2015-05-05 20:31:03 +02:00
Jef Driesen
23acddbe08 Eliminate ghost events caused by unknown events.
The newest Suunto models (e.g. D4i, D6i, D9tx and DX) support a few
additional events (type 0x15 and higher), which are not supported yet
because their interpretation isn't known.

Due to a nasty bug, these unkown events result in "ghost" events. When
such an unknown event is encountered, the sample type field isn't set
explicitely. Therefore it simply retains the value from the previous
sample, whatever that might be. If the previous sample happens to be an
event as well, then the unknown event will show up as a duplicate event.
But if the previous sample is not an event, then the resulting event
type is undefined.

This is fixed by always resetting the event type explicitely. Those
unknown events are also suppressed now and no longer delivered to the
application.

Allthough I haven't observed this bug with the Suunto Eon and Vyper,
they could be affected too.
2015-05-04 15:50:53 +02:00
Jef Driesen
ecd20ffb4c Merge branch 'ostc' 2015-05-01 11:31:07 +02:00
Jef Driesen
f24b93cd82 Parse the profile to retrieve the manual gas mixes.
The DC_FIELD_GASMIX api doesn't support the 6th manual gas very well.
Manual gas mixes are either not taken into account at all (OSTC3), or
only the last value is returned (OSTC2).

We now parse the profile data in order to retrieve all the manual gas
mixes too. Note that manual gas mixes are only included when they are
actively used during the dive. This is a small change in behaviour for
the OSTC2.

To simplify the implementation, there is an upper limit of 10 manual gas
mixes (or 15 gas mixes in total). This is an arbitrary choice, which
should be more than sufficient in practice. If it turns out to be too
small, we can always increase the number, or even make it truely
unlimited.
2015-05-01 11:29:35 +02:00
Jef Driesen
ac48210f4a Cache the fixed gas mixes too. 2015-05-01 11:29:35 +02:00
Jef Driesen
391de65d16 Cache the header data internally. 2015-05-01 11:29:35 +02:00
Jef Driesen
b832f4cf1b Cache the header and footer size internally. 2015-05-01 11:28:55 +02:00
Jef Driesen
8eba3cae3a Cache the gas mixes internally. 2015-05-01 11:28:20 +02:00
Anton Lundin
ad1c17b39d Dump function for the OSTC3
This adds a dump function for the ostc3 series computers. This function
dumps the whole external eprom, that contains the dive-headers and the
dive data.

Signed-off-by: Anton Lundin <glance@acc.umu.se>
2015-05-01 10:55:53 +02:00
Jef Driesen
c03c592a27 Merge branch 'iq700' 2015-04-29 23:06:12 +02:00
Jef Driesen
d7c89bbc39 Add support for the temperature field. 2015-04-22 08:27:41 +02:00
Jef Driesen
47874037ea Disable gas change events except for the intial mix.
For the IQ-700, the existing code for the active gas mix always results
in an out-of-range gas mix index. The index of the active gas mix is
probably stored in another bit. As a temporary workaround, we simply
assume the active gas mix is always the first gas mix. This should
already produce correct results for dives with only single gas mix.
2015-04-22 08:27:41 +02:00
Jef Driesen
311bc85645 Add support for the Tusa IQ-700.
The Tusa IQ-700 is very similar to the other Seiko based models. The
most important change is that due the smaller amount of memory (8K vs
32K), the logbook entries are only 1 byte large instead of two bytes.
2015-04-22 08:25:03 +02:00
Jef Driesen
f0974ed6bc Replace hardcoded constants with a layout descriptor. 2015-04-21 19:45:31 +02:00
Jef Driesen
9ae985a499 Fix the ringbuffer start address.
Currently the profile ringbuffer starts at the base address 0x4000, but
I believe the real start is one 0x20 byte page earlier, at 0x3FE0. I
have two reasons for this:

1. To locate the start of a dive, we always have to substract one page
from the pointers in the logbook ringbuffer. With the new base address,
they would point directly to the start of the dive, which makes a lot
more sense.

2. When comparing the divetime as stored in the header with the one
obtained by counting the number of samples, they always match except for
dives that span the ringbuffer wrap point. If those extra 0x20 bytes are
included, the counts do match again.

Unfortunately, this change breaks the assumption that the ringbuffer is
aligned to packet boundaries. As a workaround, we define a virtual
ringbuffer that is slightly larger than the actual ringbuffer, but
properly aligned. Data outside the real ringbuffer is downloaded and
then immediately dropped.
2015-04-21 19:45:31 +02:00
Jef Driesen
ad6ec1e7f5 Align all read operations to packet boundaries.
Packets have a fixed size of 0x80 bytes, while a single page is only
0x20 bytes long. Thus each read operation always returns 4 pages at
once. Now, if the end-of-profile pointer is not nicely aligned on a
packet boundary, then the download algorithm won't arrive exactly at the
start address of the ringbuffer, because the ringbuffer is properly
aligned. The consequence is that we won't even notice we reached the
ringbuffer boundary and happily continue reading outside the ringbuffer.
Oops!

This is fixed by aligning the end-of-profile pointer, which guarantees
that all read operations are now nicely aligned to packet boundaries.
2015-04-21 19:45:31 +02:00
Jef Driesen
c4233c091d Send the command and read the echo byte by byte.
When trying to send a command, the first attempt always fails. We
receive the echo, but no data packet. A second attempt usually works,
but we always get back the same data packet. That's cleary wrong.

Now, when comparing the data packets with those of the Tusa application,
I noticed something very interesting. When we request the first packet
(page 0x0000), we get:

  W: 520000
  R: 520000
  R: 00880124056202000250002890470824...19202720002000200020002000204145

The Tusa application also request this page, but the response is
completely different:

  W: 520000
  R: 520000
  R: 22182224222322092203220522112210...0000000000f021fc0000000000000045

The response we get is identical to the response that the Tusa
application gets for page 0x0052:

  W: 520052
  R: 520052
  R: 00880124056202000250002890470824...19202720002000200020002000204145

The only difference here is the echo of the command. But the echo should
be ignored, because it's generated by the pc interface, and not send by
the dive computer. This is easily verified by the fact that we always
receive an echo, even without a dive computer connected (e.g. only the
pc interface).

Notice how the command type (first byte) and page number (last byte) are
identical (0x52) for this request! I suspect that somehow the command
type ends up being interpreted as the page number. That would explain
why we're always getting the same response: as far as the device is
concerned we're always requesting page 0x52. This is probably also
related to the fact that the device doesn't respond after the first
request. It's not impossible that if the first command wasn't received
correctly and we resend the command, the device receives something that
contains parts of both attempts.

By sending the command and reading the echo byte by byte instead of all
at once, the above problem disappears.
2015-04-21 19:45:31 +02:00
Jef Driesen
edd777dbd3 Wait after changing the serial line settings.
Without the delay, the communication immediately fails. We receive the
command echo, but not the actual data packet. I suspect the device is
still be busy with the initialization and needs a bit more time before
it's ready to accept a request.
2015-04-21 19:44:01 +02:00
Jef Driesen
c4cbd19d5b Resend the command on failures. 2015-04-21 19:43:58 +02:00
Jef Driesen
327e39ed52 Merge branch 'mares' 2015-04-18 21:37:05 +02:00
Jef Driesen
3a6206e72c Relax the detection of the last dive.
We received data from a Mares Smart where the existing heuristics to
detect the last dive are not sufficient. The very last check, where the
calculated and stored are compared results in a fatal error.
2015-04-10 22:31:29 +02:00
Jef Driesen
4797ad8d9e Add support for the Mares Smart.
The Mares Smart supports not only scuba diving, but also freediving.
Because the freedive data format is fundamentally different from the
regular dives, being able to detect the type of dive in advance is very
important. For that reason, Mares moved the 4 bytes containing the dive
mode and number of samples from the beginning of the header to the end.
Except for this 4 byte shift, there are no changes for regular dives.

For the freedives, there is no real profile available, only a summary of
the entire freedive session. In an attempt to workaround this
limitation, we generate a pseudo profile in exactly the same (but ugly)
way as is done in the Mares Nemo backend.
2015-04-10 22:15:53 +02:00
Jef Driesen
e838aebc87 Add some additional DiveSystem iDive models.
These are all the models listed in the official documentation from
DiveSystem. They all share the same communication protocol and data
format.
2015-03-20 13:29:51 +01:00
Jef Driesen
a67e21dc2f Add support for two new OSTC3 variants.
The new OSTC3 (model 0x1A) is identical to the existing OSTC3, except
that the usb interface has been replaced with a bluetooth interface.

The new OSTC2 (model 0x1A) will retain the look and feel of the OSTC 2C
(e.g. plastic housing, piezo buttons and rechargable battery), but under
the hood it will use the same firmware as the OSTC3. It will also have a
bluetooth interface.
2015-03-18 13:30:35 +01:00
Jef Driesen
42808873e4 Disable alarm based gas switches for the Meridian.
The gas mix index stored in the alarm bytes is occasionally out of range
(larger than the number of available gas mixes). The index refers to one
of the disabled gas mixes. Since those are excluded now, this results in
a fatal error instead of a switch to a nonsense gas mix.

To workaround this problem, the alarm based gas switches are disabled
until we figure out how to parse them correctly.

The Chromis is almost identical to the Meridian, and will probably need
the same workaround. Although I don't have any data to confirm this,
let's just keep the two in sync.
2015-03-18 08:46:49 +01:00
Jef Driesen
c01ff9f9c6 Merge branch 'uwatec' 2015-03-12 14:13:59 +01:00
Jef Driesen
c135eb75de Implement the dive mode field.
Dives with all gas mixes disabled are flagged as gauge dives in the
Uwatec application.
2015-03-12 14:13:43 +01:00
Jef Driesen
76f93d3fe5 Ignore disabled gas mixes.
Gas mixes are disabled by setting their oxygen percentage byte to 0x00.
This is clearly an invalid gas mix, and it makes no sense to return it
back to the application.

It seems the device doesn't allow you to enable a gas mix if the
previous gas mix has already been disabled. Therefore we can simply stop
parsing the gas mixes once the first disabled gas mix has been found.
2015-03-12 14:13:43 +01:00
Jef Driesen
4fd825cdac Uwatec Aladin Tec 2G supports maximum 2 gas mixes.
According to the technical specifications, the Uwatec Aladin Tec 2G
supports maximum two gas mixes. The data appears to confirm this,
because the extra third gas mix always contains unrealistic oxygen
percentages.

However, I came across some data containing gas switches to the third
gas mix. The interesting part is that according to the Uwatec
application, this is actually a switch to the second gas mix in the
header. One possible explanation is that for models with up to 3 gas
mixes, they are labelled respectively "bottom", "travel" and "deco" mix.
But the documentation for the Aladin Tec 2G only refers to the bottom
and deco mix. So it might be that internally the index of the deco mix
is always the 3th mix, regardless of whether a travel mix is supported
or not.

If the only allowed values for the gas mix index are 0 (for the bottom
mix) or 2 (for the deco mix), then manually remapping the deco mix is
equivalent with ignoring the lowest bit. This has the advantage that the
required bitmasks and shifts are no longer different from those for the
other models.
2015-03-12 14:13:18 +01:00
Jef Driesen
8b64ce0edc Cache the parser data internally. 2015-03-12 14:13:18 +01:00
Jef Driesen
fb417ee5b5 No gas mix support for the Galileo Trimix yet.
For the Galileo Trimix we don't know yet where and how the gas mixes are
stored. Right now, we just pretend there are no gas mixes available,
which is misleading.
2015-03-12 14:13:17 +01:00
Jef Driesen
bcb2925a25 Fix the Galileo trimix detection.
Originally, I assumed that the trimix firmware update changed the model
number from 0x11 (Galileo) to 0x19 (Galileo Trimix). But that assumption
appears to be wrong because I received data from a Galileo with model
number 0x11, but with the trimix data format. Another explanation might
be that the trimix data format is not specific to the trimix firmware.

Anyway, this is easily fixed by treating both models identically.
2015-03-12 14:12:53 +01:00
Jef Driesen
5a1f1293d2 Disable tank pressure samples for the Aeris Manta.
The Aeris Manta is yet another non-air integrated model that doesn't set
the initial tank pressure to the magic value 10000.
2015-03-06 22:33:10 +01:00
Jef Driesen
90ba491c6d Merge branch 'ostc' 2015-03-06 21:45:39 +01:00
Jef Driesen
3b264d9cfd Add support for the new hardware descriptor.
The latest firmware v1.75 introduced a new hardware descriptor byte to
identify the different models based on their hardware features. This new
hardware descriptor is now used as the libdivecomputer model number. For
older firmware versions, which do not support the descriptor yet, there
is an automatic fallback to the previous method based on the serial
number.
2015-03-06 21:45:02 +01:00
Jef Driesen
bdbe95f221 Detect and report unsupported commands.
When trying to send an unsupported command, the ostc will simply ignore
the command. Instead of echoing the command byte back, the ostc will
immediately send the ready byte, to indicate it's ready to receive the
next command. We can use this to detect unsupported commands, because
the ready byte is a reserved value and guaranteed to never be a valid
command byte.

Normally we don't send invalid commands. But newer firmware version can
always introduce new commands to support new features. To maintain
backwards compatibility with older firmware versions, it's important to
be able to detect unsupported commands and provide a fallback.
2015-03-06 21:45:02 +01:00
Jef Driesen
c7d2bfc9a0 Add support for the Sherwood Amphos Air. 2015-03-04 08:13:53 +01:00
Jef Driesen
da96f0211a Fix the freedive mode for the DG03 and VT3.
The freedive/gauge bits for the Hollis DG03 and Oceanic VT3 are stored
at another location than our initial assumption.
2015-03-04 08:06:39 +01:00
Jef Driesen
f205ef736c Merge branch 'veo' 2015-02-27 10:31:17 +01:00
Jef Driesen
41834a31c7 Fix the freedive mode for the Oceanic Veo 2 and 3.
In freedive mode, the Oceanic Veo 2.0 and 3.0 have samples that are only
4 bytes long, instead of the normal 8 bytes.

The Oceanic VT3 and Hollis DG03 use the same logbook layout, and
although I haven't been able to confirm this with real data, it's very
likely they need the same fix.
2015-02-27 10:18:09 +01:00
Jef Driesen
488c396656 Fix the hour for the Oceanic Veo 2 and 3.
For BCD encoding the hour in a 12 hour clock system, only 5 bits are
required. The extra two bits are used for storing the freedive/gauge
mode.
2015-02-27 10:17:19 +01:00
Jef Driesen
678e75a05a Merge branch 'vtx' 2015-02-21 14:38:28 +01:00
Jef Driesen
bad4dd4342 Add support for the Oceanic VTX.
The Oceanic VTX is very similar to the Aeris A300 CS. The main
difference is the higher baudrate (115200 vs 38400). This is annoying
because without the correct baudrate, no communication is possible and
thus the existing autodetection based on the version packet doesn't
work. As a workaround, we now rely on the model number from the device
descriptor. The consequence is that the user must select the correct
model now (or at least a model with the same baudrate).
2015-02-19 13:47:48 +01:00
Jef Driesen
4dfca21a2b Pass the model number to the open function.
This change will be necessary for the Oceanic VTX, because it uses a
higher baudrate.

To maintain backwards compatibility, the existing function remains
unchanged and a new function is introduced instead.
2015-02-19 13:47:25 +01:00