886 Commits

Author SHA1 Message Date
Venkatesh Shukla
33710423ac Add an option to disable the example applications.
The example applications may not always be needed. An option to disable
them might be useful.

Signed-off-by: Venkatesh Shukla <venkatesh.shukla.eee11@iitbhu.ac.in>
2014-07-02 16:26:39 +02:00
Jef Driesen
6433a45bbc Fix the date/time for the Aeris Elite T3.
Commit d414da70a42afca0096e0402a426c4ac8d2a2881 added support for a
second Aeris Elite T3 variant. But the parser wasn't updated to take
into account this second model number.
2014-06-25 08:44:36 +02:00
Jef Driesen
368c138858 Fix the gas mixes for a few models.
For the Aeris Manta and Sherwood Insight, the header size should be 16
bytes smaller. Due to this mistake not only two samples were missing,
but also the byte offset for the gas mixes were wrong. This resulted in
invalid gas mixes, with oxygen percentages exceeding 100%.
2014-06-25 08:44:27 +02:00
Jef Driesen
48e73babd6 Fix the temperature for the Sherwood Wisdom 2.
The sign bit should be reversed for this model.
2014-06-20 22:22:41 +02:00
Jef Driesen
f8081f1e1f Merge branch 'gasmix' 2014-06-19 09:01:14 +02:00
Jef Driesen
f20f28e9d0 Ignore disabled gas mixes.
For the older models, gas mixes are disabled by setting their oxygen
percentage byte to 0x00 or 0xFF. Trying to parse such a byte as a valid
percentage results in an invalid gas mix.

Because the device doesn't allow you to enable a gas mix if the previous
gas mix has already been disabled, we can simply stop parsing the gas
mixes once the first disabled gas mix has been found.
2014-06-19 08:58:51 +02:00
Jef Driesen
86e9c3dfd3 Cache the initial gas mix.
The gas mode should not only be taken into account for parsing the gas
mix definitions, but also for the initial gas mix. Because the logic
needs to be kept in sync, it's convenient to have all related code in a
single place, and cache the value.
2014-06-17 21:05:23 +02:00
Jef Driesen
28135bc57a Apply the gas mode immediately.
Because the gas mode takes precedence over the individual gas mix
definitions, we can simplify the code by taking the gas mode into
account immediately when parsing the gas mixes.
2014-06-17 21:05:23 +02:00
Jef Driesen
e0e6460372 Merge branch 'dx' 2014-06-17 21:04:50 +02:00
Jef Driesen
bb2b64f5d7 Fix the length of the Suunto DX gas change event.
The Suunto DX uses 5 bytes for the 0x06 gas change event.
2014-06-17 21:03:55 +02:00
Jef Driesen
8a5bfc390d Remove the percentage variable.
There is already another variable for the O2 percentage, so re-use that
one instead.
2014-06-17 21:03:55 +02:00
Jef Driesen
e263a1c336 Improve the warning and error messages. 2014-06-17 21:03:55 +02:00
Jef Driesen
ffd1d1c8b6 Disable the gas mixes in gauge mode. 2014-06-12 08:31:19 +02:00
Cristian Ionescu-Idbohrn
1d6c933415 Another gitignore update.
Signed-off-by: Cristian Ionescu-Idbohrn <cristian.ionescu-idbohrn@axis.com>
2014-06-11 15:25:24 +02:00
Jef Driesen
8eebc0abd8 Add support for the Beuchat Voyager 2G. 2014-06-07 10:08:04 +02:00
Jef Driesen
20c874b267 Use higher resolution timestamps on Windows.
In commit 886884ab606def1183d99eca7dec8affefee635e, the custom log
function in the example applications has already been modified to use
high resolution timestamps. But I forgot about the built-in default log
function. So this is basically the same change, but now applied to the
built-in log function.
2014-05-28 15:41:21 +02:00
Jef Driesen
2e71075c5b Merge branch 'termios' 2014-05-28 15:40:41 +02:00
Jef Driesen
197b9f0942 Remove the extra check of the termios structure.
The extra memcmp check after the tcsetattr call is intended to verify
whether all the changes to the termios structure have been applied
correctly.

But for pty's, some of the termios settings make no sense at all, and
therefore the Linux kernel always does:

    tty->termios.c_cflag &= ~(CSIZE | PARENB);
    tty->termios.c_cflag |= (CS8 | CREAD);

Thus, instead of ignoring such nonsense termios settings, the kernel
changes the termios structure to reflect what pty's actually do. The
consequence is that these settings will not stick, and cause the memcmp
check to fail.

An example where this affects libdivecomputer, are the two backends that
require odd or even parity (e.g. vyper and iconhd). Here, the kernel
will clear the PARENB flag, and thus cause the memcmp check to fail.

Since this check appears to causes more trouble than it solves, let's
just remove it completely!
2014-05-28 11:11:35 +02:00
Jef Driesen
5f1a18653d Initialize the termios structure.
The previous commit exposed another issue. The termios structure may
contain padding bytes. Because the content of those padding bytes is
unspecified, they may contain some random data, which causes the memcmp
to fail.

Explicitly initializing the termios structure with memset, will also set
the padding bytes to zero.
2014-05-28 11:10:23 +02:00
Venkatesh Shukla
3001dda198 Minor error in serial_configure
Due to a minor mistake, only the first byte was being checked for
equality. Fixed it by changing position of parenthesis.

Signed-off-by: Venkatesh Shukla <venkatesh.shukla.eee11@iitbhu.ac.in>
2014-05-20 21:48:57 +02:00
Jef Driesen
48924123a6 Fix a typo in the profile ringbuffer start address.
The profile ringbuffer is supposed to be located after the logbook
ringbuffer, but due a silly typo they did overlap with 256 bytes.
2014-05-19 22:57:49 +02:00
Jef Driesen
654a909936 Fix the Mares Puck Pro memory layout descriptor.
The Mares Puck Pro uses the same memory layout as the Nemo Wide 2. See
commit 322227df7f65da8b4a962f3513e0a10b89cbe29d for more details.
2014-05-19 08:40:10 +02:00
Jef Driesen
1872b71dad Add support for ascent rate warnings.
The Cressi Leonardo does store an indicator for the ascent rate (e.g.
the number of arrows) in the upper two bits. This results in 4 possible
values, ranging from 0 to 3, with the following interpretation:

    0.0 -  3.9 m/min  No signal
    4.0 -  7.9 m/min  1 Arrow
    8.0 - 11.9 m/min  2 Arrows
   12.0+       m/min  3 Arrows (with STOP icon)

Reported-By: Nick Shore <support@mac-dive.com>
2014-05-13 10:35:06 +02:00
Jef Driesen
61e9847196 Merge branch 'ostc' 2014-05-06 22:16:59 +02:00
Jef Driesen
b7a5394e73 Add support for the new OSTC3 bailout event.
With the exception of the different event mask (single byte 0x80 vs two
byte 0x0100), the OSTC3 bailout event is identical to the OSTC2 variant.
Just as before, the new bailout event is reported to the application as
a normal gas change event.
2014-05-06 11:25:46 +02:00
Jef Driesen
4db8535e39 Use the extended sample length stored in the data.
Currently, the buffer overflow checks take into account the size of the
entire dive. But since the length of the extended sample is stored in
the data, we can actually check for overflows in each sample. The main
benefit is that errors will be caught much earlier now.

An additional advantage is that we can now easily skip any remaining
sample bytes. Normally such bytes are not present, unless a firmware
update introduces a new feature which our parser doesn't support yet.
2014-05-06 11:25:46 +02:00
Jef Driesen
5abad6e568 Add more error messages.
This makes debugging easier, because the error messages immediately
reveal where the problem is located, without needing a debugger.
2014-05-06 09:07:13 +02:00
Jef Driesen
466fb0ff6b Add more buffer overflow checks.
There are a few places left, where the contents of the buffer is
accessed without first inspecting the available length.
2014-05-06 09:03:26 +02:00
Jef Driesen
322227df7f Fix the Mares Nemo Wide 2 memory layout descriptor.
The Mares Nemo Wide 2 appears to have a slightly larger profile
ringbuffer, which extends to the end of the internal memory. It remains
to be seen whether this is also true for some of the other models. The
Mares Matrix is currently the only model where this is definitely not
the case.
2014-04-22 14:29:58 +02:00
Jef Driesen
b4cc491aee Add support for the Aeris A300. 2014-04-22 14:29:58 +02:00
Jef Driesen
80d34414a2 Merge branch 'hollistx1' 2014-04-22 14:29:01 +02:00
Jef Driesen
148f059bcb Add support for the Hollis TX1.
The Hollis TX1 has several new features compared to the other models. It
supports trimix and up to 6 different gas mixes can be configured. It
also has twice the amount of memory, which requires an extra bit for the
ringbuffer pointers.
2014-04-22 14:28:27 +02:00
Jef Driesen
3c99f55b6f Add support for trimix gas mixes. 2014-04-22 11:33:53 +02:00
Jef Driesen
c74118a922 Fix the initial gas mix for the D4i, D6i and D9tx.
The initial gas mix index has been confirmed for the D6i only. For the
other two models, it's an educated guess that the byte offset will be
identical.
2014-04-15 13:57:43 +02:00
Jef Driesen
6b912f4f7b Fix the detection of the last valid dive.
Normally, the last valid dive is followed by an empty entry with all
0xFF bytes. However, we received data from a device where a few of those
bytes are not equal to 0xFF. This causes the entry to be processed
incorrectly as a valid dive.

As a workaround, we now check the internal dive number for 0xFFFF.
2014-04-07 11:05:14 +02:00
Jef Driesen
eb12a0aa20 Remove an infinite loop.
If an unknown type byte is encountered, the offset isn't incremented,
resulting in an infinite loop. We now return an error instead.
2014-03-31 11:26:51 +02:00
Jef Driesen
1d7c79b635 Add support for the Atomic Aquatics Cobalt 2. 2014-03-30 23:09:45 +02:00
Anton Lundin
6d4893a146 Fix building for Android
This makes libdivecomputer build via Android NDK. Its currently unusable
due to the fact that Android usually doesn't provide any kernel serial
drivers.

Signed-off-by: Anton Lundin <glance@acc.umu.se>
2014-03-28 12:38:24 +01:00
Jef Driesen
5086b1781c Reduce the timeout to one second.
A packet usually takes only a few milliseconds to transfer, so one
second is still plenty of margin.
2014-03-28 10:08:22 +01:00
Jef Driesen
f0faebb3a1 Introduce an adaptive inter packet delay.
On some systems a small delay is required between receiving the response
of a packet and sending the request for the next packet. Without this
delay, almost every request fails with either a NAK or a timeout.
Retrying usually works, but also causes the download to slow down
considerable.

The root of the problem appears to be related to the FTDI low latency
setting. On Windows and Mac OS X systems, the default setting for the
latency is 16ms, while Linux defaults to a low latency setting of only
1ms. This higher latency on Windows and Mac automatically introduces a
small delay while reading the packet, and that probably happens to be
just enough to make the transfer succeed without any problems. But on
Linux, due to the low latency setting, the next request is send almost
immediately, and that causes the transfer to fail. I suspect the dive
computer may still be busy with the previous request and needs a bit
more time before it's ready to accept a new request.

To mitigate this problem, we introduce a adaptive inter packet delay.
Initially this adaptive delay is set to zero. This is to make sure we
don't affect those systems that don't need a delay at all. Now, every
time a packet fails, that's an indication the inter packet delay is too
small, and we slightly increase the value. After a few attempts we'll
automatically reach the minimal required value. To avoid that the delay
grows out of control in the case of serious trouble, it's limited at
16ms.

Note that the fixed 100ms delay before retrying a failed packet remains
in place. That's on purpose, to make sure the next attempt will always
be successful, regardless of whether the adaptive delay has already
reached its minimal value or not.
2014-03-28 10:08:13 +01:00
Jef Driesen
bfeab10515 Add support for modifying the receive latency.
Currently this isn't used or needed anywhere, but the research has been
done, and it would be silly to drop the knowledge. We may need it in the
future.
2014-03-28 09:39:26 +01:00
Jef Driesen
fa90009c29 Merge branch 'suunto' 2014-03-22 10:22:15 +01:00
Jef Driesen
ede9469316 Report the initial gas mix.
The Suunto dive computers record gas change events in the profile data.
But because there is no gas change event stored on the first sample, the
application doesn't know which gas mix is in use, until the very first
gas change event occurs.

For the Suunto HelO2, the index of the initial gas mix is stored in the
dive header. This is most likely also the case for the other models, but
I haven't found yet where exactly it is stored. As a temporary solution,
we simply assume the initial gas mix is the first gas in the list with
available gas mixes. This should be a reasonable assumption for most
dives.

Fixes ticket #2
2014-03-22 10:21:25 +01:00
Jef Driesen
d8ccfd928b Cache the gas mix data internally.
The gas mix data is used from multiple functions, and the code to parse
that data is duplicated in each function. Because this is error prone,
the code is moved to a single place, and the data cached in the parser.
2014-03-22 10:21:07 +01:00
Florian Klink
fc008312b5 Remove trailing whitespaces
Most of them appear in the disclaimers, but some are in the code as
well.
2014-03-19 09:16:07 +01:00
Janice McLaughlin
f923ec3889 Fix the gas mixes for the Oceanic OCi.
The Oceanic OCi supports 4 gas mixes instead of just 3, and they are
stored at a different offset.
2014-03-14 09:48:35 +01:00
Jef Driesen
db79a63c0d Fix a typo in the format string. 2014-03-14 09:44:10 +01:00
Jef Driesen
886884ab60 Use higher resolution timestamps on Windows.
The resolution of the GetTickCount function is limited to the resolution
of the system timer, which is typically in the range of 10 to 16
milliseconds. This is unsufficient for measuring very short time
intervals in the milliseconds range. The QueryPerformanceCounter
function provides much higher resolution timestamps. We already use it
for the half-duplex workaround.
2014-03-13 15:49:15 +01:00
Jef Driesen
c9202454bb Merge branch 'uwatec' 2014-03-09 23:05:22 +01:00
Jef Driesen
861b5652e0 Add support for parsing gas changes.
Parsing the gas switch events is somewhat complicated, because depending
on the actual model, they can be stored in different ways.

The table below lists the number of gas mixes (G), tanks (T) and alarm
bytes (A) supported by each model. Note that only the representative
model in each group is listed.

  Model         | G | T | A
  ==============|===|===|===
  Pro           | 1 | 0 | 1
  Com           | 1 | 1 | 1
  Tec           | 3 | 3 | 1
  Aladin Tec    | 1 | 0 | 2
  Aladin Tec 2G | 3 | 0 | 2
  Galileo       | 3 | 3 | 3

Models without support for multiple gasmixes only need to set the
initial gas mix correctly. Models with support for one or more tank
pressure sensors can link the gas switches to the tank switches. Models
with at least two alarm bytes can store a gas switch event in the second
alarm byte.

As can be observed from the table, some models can use several different
methods to store the gas switches. The current implementation supports
all of them. In the case of a conflict, the last used method always
takes precedence. That's simply due to the fact that each method just
sets the gasmix index, and only the final value is used. If this
approach turns out to produce wrong results, it can always be fixed
later.

The initial gasmix is always assumed to be the first configured gasmix.
2014-03-09 12:57:52 +01:00