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%.
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.
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>
Remove the device specific example applications.

These device specific applications became obsolete long time ago with
the introduction of the universal application.
Ignore excess samples with the same timestamp.

With a time based sample interval, the maximum number of samples for a
single timestamp should be constant. However in practice some devices
occasionally store one or more additional samples with the same
timestamp.

Ignoring those excess samples, allows the parser to proceed, while still
preserving the strict time based interval for the application.
Use symbolic constants for the model numbers.
Fix the dive mode detection for the Mares Nemo Air.

For the Nemo Air, a dive mode with the value 2 indicates gauge mode
instead of freedive mode. With this change, all models from the puck
family now use the same values.
Ignore disabled gas mixes.

Gas mixes that have been disabled are stored as a mix with 0% oxygen and
0% helium. This is clearly an invalid gas mix, and it makes no sense to
return it back to the application.
Modified to pass file descriptor instead of path

As an experiment, the file descriptor was passed on rather than
path to the tty. Refer
http://developer.android.com/reference/android/hardware/usb/UsbDeviceConnection.html#getFileDescriptor()
for documentation regarding file descriptor to be transferred.
The idea is that Java side of the project will obtain permission for
usage of USB device and pass it on to the native side. Using this
file descriptor, the libdivecomputer is expected to import dives.

Signed-off-by: Venkatesh Shukla <venkatesh.shukla.eee11@iitbhu.ac.in>
Revert to passing name rather than fd

As experiment 2 failed with the Error ENOTTY : Not a typewriter
we would revert to the original mechanism.
The reason behind this failure is explained by Jef.
The file descriptor given by android is actually the file
descriptor of the USB device not the tty built over it.
Hence it would not be possible to use libdivecomputer with this
file descriptor.
But maybe libusb can utilise this?

Signed-off-by: Venkatesh Shukla <venkatesh.shukla.eee11@iitbhu.ac.in>
Initial version serial_ftdi.c

This is based on serial_posix script.
There are a number of shortcomings.
Biggest of them is macro definition of VID and PID. Rather than this,
maintain a list of VID and PID of accepted FTDI devices.
Unimplemented functions like get_transmitted, send_break and set_break
return -1 on call.

For device_open(), vid pid would be better arguments than the path as
path is not too helpful for libftdi and libusb.

serial_enumerate gives back the path of all the devices present on all
hubs on android. Basically, all the files present in all the subfolders
of /dev/bus/usb.
A better implementation would be a set of ftdi devices attached to the
android. This could be done either using jni by enumerate_device in
android.cpp or using libusb and passing vid pid as an argument.

Signed-off-by: Venkatesh Shukla <venkatesh.shukla.eee11@iitbhu.ac.in>
Check for libftdi and build for android

Added check for libftdi during configure.
Suitable modifications to enable cross building for android platform.

Signed-off-by: Venkatesh Shukla <venkatesh.shukla.eee11@iitbhu.ac.in>
Corrected include statement for ftdi.h

Use libusb.h instead of libusb-1.0/libusb.h

Signed-off-by: Venkatesh Shukla <venkatesh.shukla.eee11@iitbhu.ac.in>
Corrections in serial_open and serial_set_timeout

ftdi_context->timeout is the timeout used while libusb_bulk_transfer.
On the other hand, libdivecomputer context is used internally by
libdivecomputer. So inappropriate to set both here. By default libftdi
sets a timeout of 5000 ms on both read and write.

Usage of struct ftdi_context was wrong. Fixed it.

Signed-off-by: Venkatesh Shukla <venkatesh.shukla.eee11@iitbhu.ac.in>
Finally a working version. Try again on no data.

ftdi_read_data returns 0 if no data is received from
the device. The existing code understood it as timeout errror.
Removing this check might end up in an infinite loop. But it works
in OSTC3. This should be checked further.
Cross compilation of libdivecomputer on android and running it
gives the results same as the ones on pc.

Signed-off-by: Venkatesh Shukla <venkatesh.shukla.eee11@iitbhu.ac.in>
Check multiple pids while opening device

libftdi returns -3 when it could not find any device corresponding to
the pid and vid given. (Different from -3 of libusb which means you do
not have permissions to access the device)
Using this value, check among a list of accepted pids. VID is that of
ftdi ( file is called serial_ftdi :)
There is a problem when multiple devices are connected. It uses the
first one it can find in the list. This might not be correct always.

Signed-off-by: Venkatesh Shukla <venkatesh.shukla.eee11@iitbhu.ac.in>
Added custom pids of divecomputers

Some divecomputer manufacturers use custom pid for their ftdi chips.
Some of them are Cressi (Leonardo), Suunto and Oceanic.
These are added to accepted_pids.

Signed-off-by: Venkatesh Shukla <venkatesh.shukla.eee11@iitbhu.ac.in>
Again changed to pass usb file descriptor

As experiments continue, I visit this technique again.
But instead of using the file descriptor as tty device,
now using it to make a libusb_device. This could help us
in talking with the usb device after appropriate permissions
are taken. Crossed fingers.

Signed-off-by: Venkatesh Shukla <venkatesh.shukla.eee11@iitbhu.ac.in>
libftdi1 in pkg-config when building for android

If you are building for android, you would need libftdi package.
Hence add this in Required.private so that it may be included
automatically while cross compilation.

Signed-off-by: Venkatesh Shukla <venkatesh.shukla.eee11@iitbhu.ac.in>
Bug causing indefinite block on serial_close android

Mistakenly, I was trying to close the ftdi device after freeing its ftdi
context. This was causing an indefinite blockage on serial_close function call
at libusb_release_interface. Fixed it.

Signed-off-by: Venkatesh Shukla <venkatesh.shukla.eee11@iitbhu.ac.in>