The max depth is stored in imperial units (feet), and should be
converted into metric units (meter). But for some reason this unit
conversion was omitted.
Apparantly there are also two different type of serial numbers present,
and their interpretation depends on the application. The Windows Dive
Organizer application shows both a serial number (byte offset 0x04) and
a warranty number (byte offset 0x0C). However, the Mac OS X Divers'
Diary application shows the number at byte offset 0x0C as the serial
number. Very confusing. For now, we just stick to the number at byte
offset 0x0C, because that's the number that is shown by the device
itself.
If the first attempt fails, that might indicate the device isn't ready
yet to service requests. In that case immediately retrying again isn't
the right solution. Adding a small delay seems to increase the success
rate, so it's a good idea anyway, regardless of the underlying reason.
Apparantly, the windows wingdi.h header file already defines the
ERROR macro. By defining the NOGDI macro before including the
windows.h header file, we can prevent the wingdi.h file from being
included and thus avoid the warning. We don't need that header for
anything anyway.
Because the libusb header file includes the windows.h file
explicitly, it needs the same fix.
Apparently some older firmware versions don't support the salinity
setting. Because unused bytes are initialized with zero, the salinity
adjustment results in a division by zero, which converts all depth
values to infinity.
To fix this regression, the salinity factor is first checked for valid
values. If the value is out of range, no salinity adjustment is done,
and the previous behaviour is retained.
There appears to be two very different versions of the Sherwood Insight.
The old Insight needs the veo250 backend, while the newer Insight 2
needs the atom2 backend. Currently only the newer version was included
in the list of supported devices, and to increase the confusion it was
even named after the old version.
With this patch, the old version is added to the list, and the new
version is renamed to "Insight 2".
This now uses the same formula as the OSTC uses internally which will get
the values reported by libdivecomputer to be consistent with what is
displayed on the OSTC.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
When the gas model setting is set to air, the individual gas mix
definitions retain their previous (non-air) values. This is convenient
to avoid having to adjust the gas mixes again on your next nitrox or
mixed gas dive. But the consequence is that for air dives, the gas model
should take precedence over the individual gas mix definitions, and a
single mix with air is returned instead.
We received data from a device where the end-of-profile marker is
missing. Because the device fails to locate the last dive, it goes into
an infinite loop, and keeps sending the same sequence of dives over and
over again. As a result, we receive more data than expected, and the
assert in the progress event is triggered.
We now keep track of the maximum number of bytes remaining and abort
once the limit is passed. The values of the progress events are capped
at the maximum value to avoid the assertion.
When trying to continue when no dives are available, malloc() will be
called to allocate zero bytes. The result is implementation defined and
may return a NULL pointer. Since that would be interpreted as an error,
it's safer to finish immediately.
If the maximum availalbe buffer size is zero, no data can be written
(not even the NULL terminator), and a negative values should be returned
to indicate truncation.
By default, the universal application will always log error and warning
messages, but the loglevel can be increased to also log info and debug
messages.
The main logging function isn't really suitable for generating inline
hexdumps directly from the binary data. There is simply no format string
available for converting array data types with just a single printf
call.
A possible solution would be to require the caller to perform the string
conversion before calling the standard logging function. But that's not
acceptable, because it doesn't play well with the ability to disable the
logging at compile time, requires extra memory and clutters the calling
code unneccessary.
The new function is a compromise which sacrifices flexibility for
simplicity, by using a hardcoded output format with a custom prefix.
It's not a perfect solution, but it works well enough for the intended
purpose.
Pseudo terminals are very convenient for testing purposes, but they are
not fully compatible with real serial (or even usb-serial) hardware.
With the new option, some workarounds can be enabled to hide the
differences and increase compatibility. Although these workarounds
shouldn't cause any problems in production builds, the advise is to
disable this feature.
A few ioctl's are not supported for pseudo terminals. They fail with
EINVAL (Linux) or ENOTTY (Mac OS X). Since these specific error codes
should not occur under normal conditions, they are simply ignored when
pseudo terminal support is enabled.
The TIOCEXCL ioctl (exclusive access) is also problematic. The TIOCEXCL
setting is shared between the master and slave side of the pty. When the
setting is applied on the slave side, it persists for as long as the
master side remains open. The result is that re-opening the slave side
will fail with EBUSY, unless the process has root priviliges. Since this
is very inconvenient, the TIOCEXCL setting is not used when pseudo
terminal support is enabled.
With exclusive access mode, no further open() operations on the terminal
are permitted, except for a process with root priviliges. Non-root
processes will fail with EBUSY. This change will prevent other processes
from accidentally messing up the communication. It also makes the
behaviour similar to Windows, where serial ports are always opened with
exclusive access.
I forgot to update the device and parser initialization functions to
store the context pointer into the objects. As a result, the internal
context pointers were always NULL.
I forgot to update the dummy IrDA backend with the latest changes. The
error, init and cleanup functions have been removed, and the
irda_socket_open function now takes a context pointer.
The status codes in the new EXITCODE macro were not updated to use the
new constants with the namespace prefix. As a result building fails when
compiling with libusb support.
The non-standard vsnprintf implementation provided by MSVC doesn't
matches the C99 function. The wrapper function provides a consistent
interface on top of the native functions.
When the logging is disabling, several compiler warnings regarding
unused variables appear. With the cast to void and sizeof trick the
warnings are silenced without causing any side effects.
With the new option, the library can be compiled with the entire
logging infrastructure disabled. The public api remains unchanged, but
the internal logging functions will have no effect anymore.
In practice the overhead of the logging functions should be quite
small, and disabling the logging at runtime might be more convenient.
Especially because troubleshooting will become much harder without any
logging.
The public api is changed to require a context object for all
operations. Because other library objects store the context pointer
internally, only the constructor functions need an explicit context
object as a parameter.
The new convenience function provides a centralized and threadsafe
function for logging system errors. The previous functions are
deprecated and will be removed after the transition to the new context
based logging.
An application can now register an application defined callback
function, which will perform the actual logging. This provides
additional flexibility compared to logging to stderr with a hardcoded
format. Applications can now easily display the messages in their user
interface, customize the format, etc.
Although the internal logging function is a printf like function, the
arguments are converted into a plain string before being passed to the
callback function. This greatly improves interoperability with
programming languages which don't support C style variadic functions
(e.g. Python, C#, etc).
With the introduction of a context object, library initialization and
shutdown can be performed without requiring any global state. A single
process can use multiple independent contexts without any problems. The
lack of a global state also improves the thread-safety of the library.
At the moment, the new context object is primary used to implement an
improved logging system.