51 Commits

Author SHA1 Message Date
Jef Driesen
6845d9b77c Fix the Mares Puck 2 memory layout descriptor.
The Mares Puck 2 uses the same memory layout as the Nemo Wide 2. See
commit 322227df7f65da8b4a962f3513e0a10b89cbe29d for more details.
2014-08-21 23:41:20 +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
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
9394773cd2 Increase the packet size again for the Icon HD.
The switch from downloading the entire data with a single large packet
to multiple smaller 256 byte packets, resulted in a considerable
performance regression. In one particular case, the difference was a
factor 6.7 slower!

I performed a small tests (using an Icon HD Net Ready) with 256, 1024
and 4096 byte packets, and the total time was respectively 21.0, 11.3
and 6.5 seconds. For a single large packet, the total time is only 5.9
seconds. Thus the difference with a 4096 byte packet is negligible.
2014-02-21 21:22:53 +01:00
Jef Driesen
991d0180d8 Autodetect the model using the version packet.
The model number stored in the main memory isn't always the most
reliable source of information, because there are devices where the
model number has not been filled in properly. Instead, we check the
product name in the version packet against the list with valid names,
and return the corresponding model number.

As an additional advantage, we no longer depend on the model number
supplied by the application for selecting the correct memory layout.
Nevertheless, the model parameter is kept for backwards compatibility.
2014-02-21 21:22:53 +01:00
Jef Driesen
2049bdb836 Remove an unnecessary function. 2014-02-21 21:22:53 +01:00
Jef Driesen
c718abbe06 Use the same packet size for all models.
The recommended packet size is 256 bytes, which matches the maximal
amount of data that can be read back from the internal memory chip.
Larger requests are split by the firmware into multiple blocks of
maximum 256 bytes.

Note that initially, we already used 256 byte packets for the newer
models, but it seems this was accidentally changed to only 64 bytes in
commit ad0e187c0c932121efa50763afc02771633cbd61.

The main benefit of this change is a simplification of the code, because
now there is no longer a difference between the Icon HD and Matrix
variant of the protocol.
2014-02-21 21:22:52 +01:00
Jef Driesen
c93314026c Use the same standard baudrate for all models.
The Mares Icon HD use a processor with integrated USB circuit, which
presents itself to the host system as a CDC-ACM device. Since there is
no external usb-serial chip involved, the baudrate and other serial
line parameters are irrelevant. By choosing the same settings as the
later models, which do use an usb-serial chip, we can completely avoid
the problem of unresponsive devices due to using the wrong baudrate.
2014-02-21 21:22:52 +01:00
Jef Driesen
85fd0c524f Fix the memory layout descriptors.
The profile ringbuffer appears to be slightly smaller than expected for
some models. For the Mares Matrix (and all compatible devices) it ends
earlier, while for the Icon HD Net Ready it starts later.

This bug resulted in missing dives, because all remaining dives were
getting dropped once a dive that crossed the ringbuffer boundary was
reached.
2013-09-09 15:05:58 +02:00
Jef Driesen
b35e07b71b Add cancellation support to several backends.
Some backends are technically capable of supporting cancellation, but
still lacked the necessary code to enable it.
2013-09-03 20:13:49 +02:00
Alexander Neumann
37cb54c376 Add Mares Puck 2 dive computer
This dive computer has the same enclosure as the Mares Puck, but the
wire protocol is that of the Puck Pro. The original software identifies
it as a "Mares Puck 2", and the handshake string also contains the
sequence "PUCK 2", so this string is used to identify the device.
2013-08-12 13:11:07 +02:00
Jef Driesen
50fc64ac59 Limit the memory capacity to 256K.
The Mares Matrix, Puck Pro and Nemo Wide 2 have only 256K of memory,
which is 4 times less compared to the Icon HD. However for some unknown
reason, trying to download 1024K succeeds, and these devices just
repeat the same data 4 times. That's why we never noticed the
difference in memory capacity before.
2013-05-11 07:12:47 +02:00
Jef Driesen
ad0e187c0c Replace the hardcoded constants with a layout descriptor.
A side effect is that the mares_iconhd_extract_dives function now
requires a valid device handle. This shouldn't cause any real problems
because this function will likely become private some day.
2013-05-09 22:30:23 +02:00
Jef Driesen
6419e189a4 Add a single isinstance function per object type.
Currently, each backend has it's own function to verify whether the
object vtable pointer is the expected one. All these functions can be
removed in favor of a single isintance function in the base class,
which takes the expected vtable pointer as a parameter.

Functions which are called through the vtable, don't need to verify the
vtable pointer, and those checks are removed.
2013-04-16 12:18:54 +02:00
Jef Driesen
007479fc92 Rename the backend structure to vtable.
The term "backend" can be confusing because it can refer to both the
virtual function table and the device/parser backends. The use of the
term "vtable" avoids this.
2013-04-16 12:18:53 +02:00
Jef Driesen
e5fde4c57d Merge branch 'release-0.2'
Integrate the bugfixes from the stable branch.
2013-02-04 19:14:24 +01:00
Jef Driesen
173390ed05 Decode the serial number as a 32 bit number.
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.
2013-01-13 06:21:13 +01:00
Jef Driesen
1e77d92307 Add support for the Mares Puck Pro. 2013-01-06 09:29:33 +01:00
Jef Driesen
59bfb0f318 Add support for the Mares Matrix.
The Matrix uses the same communication protocol as the Nemo Wide 2,
except that the sending the request packets with just a single write
operation doesn't seem to work. That's very surprising because it
caused no problems for the Nemo Wide 2 or the Icon HD!

The first two bytes of each request packet are probably some kind of
command type. These two bytes are answerred immediately with an ACK
byte (0xAA). Once this ACK byte has been received, the payload of the
command (if any) can be sent, and finally the response packet can be
received.

I suspect that when trying to send the entire command at once, the
device somehow doesn't receive the payload bytes correctly. Maybe it's
still busy processing those first two bytes, which causes the remainder
of the packet to get dropped? That might explain why the version
commands is not affected, because it doesn't have any payload bytes!
2013-01-05 23:32:57 +01:00
Jef Driesen
56b7730773 Add a new vendor event.
The new vendor event provides a mechanism to deliver auxiliary data,
which is automatically retrieved during the data transfer, but not
accessible through the library interface otherwise. Possible examples
include handshake data and/or device identification data.

This event is mainly intended for diagnostic purposes, in combination
with the memory dumping support. Very few applications will actually
need it for anything else.
2012-12-27 12:10:45 +01:00
Jef Driesen
3d3c3f6039 Add support for the Mares Nemo Wide 2.
The Nemo Wide 2 uses the same communication protocol as the Icon HD,
except for two differences:

The Nemo Wide 2 requires a different baudrate and parity setting.
Unfortunately it doesn't seem possible to autodetect the correct
protocol variant at runtime. Attempting to proceed with incorrect
settings will render the device unresponsive and requires a battery
reset to recover.Therefore the model code needs to be provided as an
extra parameter, when opening the connection.

The Nemo Wide 2 also appears to have trouble downloading the entire
memory with a single request. Therefore the single large request is
split into many smaller ones. The offical Mares application uses 256
byte packets, and so do we. The Icon HD keeps using the large packets
because they are significant faster.

The extra model parameter breaks backwards compatibility!
2012-12-22 13:46:24 +01:00
Jef Driesen
985323eefb Move the version function to the device specific api.
The version function requires device specific knowledge to use it (at
least the required buffer size), it is already called internally when
necessary, and only a few backends support it. Thus there is no good
reason to keep it in the high-level public api.
2012-12-05 16:07:32 +01:00
Jef Driesen
550e37d0b5 Remove the page, packet and memory size macros from the public api.
These macros are used internally and don't need to be exposed. In some
cases, the actual values are not even constant, but dependant on the
model and/or the firmware version.
2012-12-05 16:07:32 +01:00
Jef Driesen
cd31ff9dff Properly store the context pointer internally.
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.
2012-08-28 08:44:47 +02:00
Jef Driesen
38c7b022cd Integrate the context object in the serial code. 2012-08-27 23:08:38 +02:00
Jef Driesen
53e9d72a40 Integrate the context object in the library.
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.
2012-08-27 23:08:38 +02:00
Jef Driesen
2095a2d10e Merge branch 'release-0.1'
Integrate the bugfixes from the stable branch.
2012-08-27 22:58:52 +02:00
Jef Driesen
c821d40144 Introduce a namespace prefix for the high-level public api.
Adding the "dc_" namespace prefix (which is of course an abbreviation
for libdivecomputer) should avoid conflicts with other libraries. For
the time being, only the high-level device and parser layers are
changed.
2012-06-21 21:42:37 +02:00
Jef Driesen
163d383332 Use a common backend type for the device and parser layers. 2012-06-21 21:42:37 +02:00
Jef Driesen
9136a52835 Use common status codes for the device and parser layers. 2012-06-21 21:42:34 +02:00
Jef Driesen
e65025b501 Separate private and public headers.
The public header files are moved to a new subdirectory, to separate
the definition of the public interface from the actual implementation.
Using an identical directory layout as the final installation has the
advantage that the example code can be build outside the project tree
without any modifications to the #include statements.
2012-06-21 21:39:24 +02:00
Jef Driesen
80f5c7025e Fix the detection of the last dive.
It looks like the Icon HD erases old dives partially with 0xFF bytes
before overwriting them with new dives. If the head of the oldest dive
has been erased, the length field which is stored in the first 4 bytes
is erased as well, and we can use it to detect the last dive.
2012-06-19 23:00:30 +02:00
Jef Driesen
ee4f105a94 Revert back to a standard baudrate on Unix.
The linux USB CDC-ACM driver, which is used by the Mares Icon HD
interface, doesn't support the ioctl's to configure a custom baudrate.
But since the actual baudrate doesn't seem to matter at all, we revert
back to the nearest standard baudrate.

Because custom baudrates are confirmed to be supported on Windows and
Mac OS X, those platforms can keep using the non-standard baudrate.
2012-01-20 22:44:45 +01:00
Jef Driesen
0ea9f5e8ca Try to correct an invalid model code.
We received data from an Icon HD Net Ready with a model code equal to
0xFF, which is an invalid value. Fortunately we can figure out the
correct model code from the data in the version packet.
2011-11-03 21:17:30 +01:00
Jef Driesen
8f2e3265fe Add read support for the Mares Icon HD. 2011-10-23 08:11:57 +02:00
Jef Driesen
f526cdd3d9 Add support for the Mares Icon HD Net Ready. 2011-09-24 13:49:18 +02:00
Jef Driesen
4ed8a6963c Store the version packet internally. 2011-09-24 13:49:18 +02:00
Jef Driesen
1ce8dec1d8 Exclude the 4 byte length from the sample data.
Correctly skip the 4 byte length in front of the sample data. The
previous code happened to work by accident, because the header after the
sample data was assumed to be 4 bytes larger, and thus those two errors
cancelled each other out.
2011-09-24 13:49:18 +02:00
Jef Driesen
786e4a7ae4 Initialize memory before use. 2011-09-24 13:49:13 +02:00
Jef Driesen
bc756d7663 Use the same baudrate on Unix and Windows.
With the support for custom baudrates on all systems, there is no need
anymore to use the nearest standard baudrate. Using the exact baudrate
should make the communication more reliable on Unix systems.
2011-08-12 22:47:07 +02:00
Jef Driesen
154f767a9c Convert assertions into error codes. 2011-01-08 23:40:15 +01:00
Jef Driesen
9588f7db01 Send the version command at startup. 2010-12-26 23:39:51 +01:00
Jef Driesen
96a93c26db Improve the detection of the last dive. 2010-12-25 20:36:48 +01:00
Jef Driesen
bb8255a116 Search for the end of te profile ringbuffer.
Because some devices appear to store the end-of-profile pointer at
different locations, we search all know positions for a valid value.
2010-12-25 20:36:48 +01:00
Jef Driesen
685660e42a Add fingerprint support for the Mares Icon HD. 2010-11-14 10:17:40 +01:00
Jef Driesen
c462e75c8c Improve the foreach function for the Mares Icon HD.
With the knowledge of the end of profile pointer and the number of
samples, the ringbuffer can be traversed backwards and the start of the
ringbuffer doesn't have to be fixed anymore.
2010-11-09 22:49:08 +01:00
Jef Driesen
887d744e6d Use a more consistent typedef in the serial and irda backends. 2010-10-04 23:08:39 +02:00
Jef Driesen
15bad40976 Add a devinfo event for the Mares Icon HD. 2010-10-04 23:08:02 +02:00
Jef Driesen
bae20d75a3 Adjust the baudrate for Unix systems.
The termios interface does not support setting a baudrate of 256000 bps,
but using the nearest supported baudrate appears to work fine too.
2010-09-19 15:31:50 +02:00
Jef Driesen
a24fd313ae Add the foreach function for the Mares Icon HD.
Note that this implementation will fail if the ringbuffer doesn't start
at the fixed address 0xA000. This is very likely to occur once the
ringbuffer is filled completely and the device starts to overwrite old
data.
2010-09-19 15:22:11 +02:00