Skip to content

Commit

Permalink
Merge branch 'garmin-descent' into Subsurface-NG
Browse files Browse the repository at this point in the history
Merge the initial Garmin Descent Mk1 support.

This actually works well enough to be useful, even though there are a
few ugly details yet to be sorted out.

The download itself is fairly complete, but all event handling is
currently missing (warnings, gas changes, things like that).

Also, because of how libdivecomputer works, the "downloading" of dives
is entirely separate from the "parsing" of dives in the libdivecomputer
world.  And that is actually problematic for the Garmin Descent
downloader, because you actually need to parse the data to even figure
out whether it's actually a dive at all!

The Garmin Descent is also a fitness and general excercise tracker, so
people can (and do) use it for other sports than just diving, and so the
activities we download may end up not being dives at all, but other
events.

But before we parse them, we don't know, and we aren't really supposed
to parse them until after we've passed the data to the application and
it passes it back for parsing.  Nasty chicken-and-egg problem there..

So right now non-diving activities will just show up as very short
and/or shallow dives.

This is fixable by just parsing things an extra time, but I really wish
libdivecomputer would just stop thinking that downloading and parsing
are separate events.

* garmin-descent:
  Add dc_usb_storage_open to the symbols list
  garmin: only record gasmixes for cylinders that aren't enabled
  garmin: don't emit fake device info and vendor event
  garmin: add support for downloading gas mixes
  garmin: add GPS coordinate data and improve parser_get_field() reports
  garmin: actually start using the parsed data
  garmin: turn all the remaining unrecognized fields into DEBUG messages
  garmin: add a lot of new field definitions
  garmin: teach the parser to show undefined values for unknown fields too
  garmin: fix file length header parsing
  garmin: teach the parser about invalid values and more dates
  garmin: some fields are defined in all message types
  Garmin: start parsing definition records
  Garmin Descent Mk1: flesh out the actual downloading part
  Add Garmin Descent Mk1 skeleton
  Add 'USB storage' transport enumeration
  • Loading branch information
torvalds committed Aug 31, 2018
2 parents 63cd80c + fe2a43e commit f6ea5f5
Show file tree
Hide file tree
Showing 14 changed files with 1,544 additions and 1 deletion.
4 changes: 4 additions & 0 deletions examples/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ static const backend_table_t g_backends[] = {
{"idive", DC_FAMILY_DIVESYSTEM_IDIVE, 0x03},
{"cochran", DC_FAMILY_COCHRAN_COMMANDER, 0},
{"divecomputereu", DC_FAMILY_TECDIVING_DIVECOMPUTEREU, 0},
{"descentmk1", DC_FAMILY_GARMIN, 0},
};

static const transport_table_t g_transports[] = {
Expand All @@ -98,6 +99,7 @@ static const transport_table_t g_transports[] = {
{"irda", DC_TRANSPORT_IRDA},
{"bluetooth", DC_TRANSPORT_BLUETOOTH},
{"ble", DC_TRANSPORT_BLE},
{"usbstorage",DC_TRANSPORT_USBSTORAGE},
};

const char *
Expand Down Expand Up @@ -536,6 +538,8 @@ dctool_iostream_open (dc_iostream_t **iostream, dc_context_t *context, dc_descri
return dctool_irda_open (iostream, context, descriptor, devname);
case DC_TRANSPORT_BLUETOOTH:
return dctool_bluetooth_open (iostream, context, descriptor, devname);
case DC_TRANSPORT_USBSTORAGE:
return dc_usb_storage_open (iostream, context, devname);
default:
return DC_STATUS_UNSUPPORTED;
}
Expand Down
8 changes: 7 additions & 1 deletion include/libdivecomputer/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,13 @@ typedef enum dc_transport_t {
DC_TRANSPORT_USBHID = (1 << 2),
DC_TRANSPORT_IRDA = (1 << 3),
DC_TRANSPORT_BLUETOOTH = (1 << 4),
DC_TRANSPORT_BLE = (1 << 5)
DC_TRANSPORT_BLE = (1 << 5),
DC_TRANSPORT_USBSTORAGE= (1 << 6),
} dc_transport_t;

// Idiotic enums can't be queried
#define DC_TRANSPORT_USBSTORAGE DC_TRANSPORT_USBSTORAGE

typedef enum dc_family_t {
DC_FAMILY_NULL = 0,
/* Suunto */
Expand Down Expand Up @@ -103,6 +107,8 @@ typedef enum dc_family_t {
DC_FAMILY_COCHRAN_COMMANDER = (14 << 16),
/* Tecdiving */
DC_FAMILY_TECDIVING_DIVECOMPUTEREU = (15 << 16),
/* Garmin */
DC_FAMILY_GARMIN = (16 << 16),
} dc_family_t;

#ifdef __cplusplus
Expand Down
3 changes: 3 additions & 0 deletions include/libdivecomputer/iostream.h
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,9 @@ dc_iostream_sleep (dc_iostream_t *iostream, unsigned int milliseconds);
dc_status_t
dc_iostream_close (dc_iostream_t *iostream);

dc_status_t
dc_usb_storage_open (dc_iostream_t **out, dc_context_t *context, const char *name);

#ifdef __cplusplus
}
#endif /* __cplusplus */
Expand Down
12 changes: 12 additions & 0 deletions msvc/libdivecomputer.vcproj
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,14 @@
RelativePath="..\src\tecdiving_divecomputereu_parser.c"
>
</File>
<File
RelativePath="..\src\garmin.c"
>
</File>
<File
RelativePath="..\src\garmin_parser.c"
>
</File>
<File
RelativePath="..\src\timer.c"
>
Expand Down Expand Up @@ -828,6 +836,10 @@
RelativePath="..\src\tecdiving_divecomputereu.h"
>
</File>
<File
RelativePath="..\src\garmin.h"
>
</File>
<File
RelativePath="..\src\timer.h"
>
Expand Down
2 changes: 2 additions & 0 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,12 @@ libdivecomputer_la_SOURCES = \
buffer.c \
cochran_commander.h cochran_commander.c cochran_commander_parser.c \
tecdiving_divecomputereu.h tecdiving_divecomputereu.c tecdiving_divecomputereu_parser.c \
garmin.h garmin.c garmin_parser.c \
socket.h socket.c \
irda.c \
usbhid.c \
bluetooth.c \
usb_storage.c \
custom.c

if OS_WIN32
Expand Down
1 change: 1 addition & 0 deletions src/context.c
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,7 @@ dc_context_get_transports (dc_context_t *context)
#elif defined(HAVE_LIBUSB) && !defined(__APPLE__)
| DC_TRANSPORT_USBHID
#endif
| DC_TRANSPORT_USBSTORAGE
#ifdef _WIN32
#ifdef HAVE_AF_IRDA_H
| DC_TRANSPORT_IRDA
Expand Down
16 changes: 16 additions & 0 deletions src/descriptor.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ static int dc_filter_suunto (dc_transport_t transport, const void *userdata);
static int dc_filter_shearwater (dc_transport_t transport, const void *userdata);
static int dc_filter_hw (dc_transport_t transport, const void *userdata);
static int dc_filter_tecdiving (dc_transport_t transport, const void *userdata);
static int dc_filter_garmin (dc_transport_t transport, const void *userdata);

static dc_status_t dc_descriptor_iterator_next (dc_iterator_t *iterator, void *item);

Expand Down Expand Up @@ -328,6 +329,8 @@ static const dc_descriptor_t g_descriptors[] = {
{"Cochran", "EMC-20H", DC_FAMILY_COCHRAN_COMMANDER, 5, DC_TRANSPORT_SERIAL, NULL},
/* Tecdiving DiveComputer.eu */
{"Tecdiving", "DiveComputer.eu", DC_FAMILY_TECDIVING_DIVECOMPUTEREU, 0, DC_TRANSPORT_SERIAL | DC_TRANSPORT_BLUETOOTH, dc_filter_tecdiving},
/* Garmin */
{"Garmin", "Descent Mk1", DC_FAMILY_GARMIN, 0, DC_TRANSPORT_USBSTORAGE, dc_filter_garmin},
};

static int
Expand Down Expand Up @@ -467,6 +470,19 @@ static int dc_filter_tecdiving (dc_transport_t transport, const void *userdata)
return 1;
}

static int dc_filter_garmin (dc_transport_t transport, const void *userdata)
{
static const dc_usb_desc_t usbhid[] = {
{0x091e, 0x2b2b}, // Garmin Descent Mk1
};

if (transport == DC_TRANSPORT_USBSTORAGE) {
return dc_filter_internal_usb ((const dc_usb_desc_t *) userdata, usbhid, C_ARRAY_SIZE(usbhid));
}

return 1;
}

dc_status_t
dc_descriptor_iterator (dc_iterator_t **out)
{
Expand Down
4 changes: 4 additions & 0 deletions src/device.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
#include "divesystem_idive.h"
#include "cochran_commander.h"
#include "tecdiving_divecomputereu.h"
#include "garmin.h"

#include "device-private.h"
#include "context-private.h"
Expand Down Expand Up @@ -207,6 +208,9 @@ dc_device_open (dc_device_t **out, dc_context_t *context, dc_descriptor_t *descr
case DC_FAMILY_TECDIVING_DIVECOMPUTEREU:
rc = tecdiving_divecomputereu_device_open (&device, context, iostream);
break;
case DC_FAMILY_GARMIN:
rc = garmin_device_open (&device, context, iostream);
break;
default:
return DC_STATUS_INVALIDARGS;
}
Expand Down
Loading

0 comments on commit f6ea5f5

Please sign in to comment.