Merge branch 'iostream'

This commit is contained in:
Jef Driesen 2018-04-03 21:44:49 +02:00
commit 0c5cf94b10
107 changed files with 1307 additions and 1511 deletions

View File

@ -12,6 +12,7 @@ dctool_SOURCES = \
dctool_help.c \ dctool_help.c \
dctool_version.c \ dctool_version.c \
dctool_list.c \ dctool_list.c \
dctool_scan.c \
dctool_download.c \ dctool_download.c \
dctool_dump.c \ dctool_dump.c \
dctool_parse.c \ dctool_parse.c \

View File

@ -19,6 +19,7 @@
* MA 02110-1301 USA * MA 02110-1301 USA
*/ */
#include <stdlib.h>
#include <string.h> #include <string.h>
#include <stdio.h> #include <stdio.h>
@ -27,6 +28,11 @@
#include <fcntl.h> #include <fcntl.h>
#endif #endif
#include <libdivecomputer/serial.h>
#include <libdivecomputer/bluetooth.h>
#include <libdivecomputer/irda.h>
#include <libdivecomputer/usbhid.h>
#include "common.h" #include "common.h"
#include "utils.h" #include "utils.h"
@ -44,6 +50,11 @@ typedef struct backend_table_t {
unsigned int model; unsigned int model;
} backend_table_t; } backend_table_t;
typedef struct transport_table_t {
const char *name;
dc_transport_t type;
} transport_table_t;
static const backend_table_t g_backends[] = { static const backend_table_t g_backends[] = {
{"solution", DC_FAMILY_SUUNTO_SOLUTION, 0}, {"solution", DC_FAMILY_SUUNTO_SOLUTION, 0},
{"eon", DC_FAMILY_SUUNTO_EON, 0}, {"eon", DC_FAMILY_SUUNTO_EON, 0},
@ -81,6 +92,14 @@ static const backend_table_t g_backends[] = {
{"cochran", DC_FAMILY_COCHRAN_COMMANDER, 0}, {"cochran", DC_FAMILY_COCHRAN_COMMANDER, 0},
}; };
static const transport_table_t g_transports[] = {
{"serial", DC_TRANSPORT_SERIAL},
{"usb", DC_TRANSPORT_USB},
{"usbhid", DC_TRANSPORT_USBHID},
{"irda", DC_TRANSPORT_IRDA},
{"bluetooth", DC_TRANSPORT_BLUETOOTH},
};
const char * const char *
dctool_errmsg (dc_status_t status) dctool_errmsg (dc_status_t status)
{ {
@ -145,6 +164,41 @@ dctool_family_model (dc_family_t type)
return 0; return 0;
} }
dc_transport_t
dctool_transport_type (const char *name)
{
for (size_t i = 0; i < C_ARRAY_SIZE (g_transports); ++i) {
if (strcmp (name, g_transports[i].name) == 0)
return g_transports[i].type;
}
return DC_TRANSPORT_NONE;
}
const char *
dctool_transport_name (dc_transport_t type)
{
for (size_t i = 0; i < C_ARRAY_SIZE (g_transports); ++i) {
if (g_transports[i].type == type)
return g_transports[i].name;
}
return NULL;
}
dc_transport_t
dctool_transport_default (dc_descriptor_t *descriptor)
{
unsigned int transports = dc_descriptor_get_transports (descriptor);
for (size_t i = 0; i < C_ARRAY_SIZE (g_transports); ++i) {
if (transports & g_transports[i].type)
return g_transports[i].type;
}
return DC_TRANSPORT_NONE;
}
void void
dctool_event_cb (dc_device_t *device, dc_event_type_t event, const void *data, void *userdata) dctool_event_cb (dc_device_t *device, dc_event_type_t event, const void *data, void *userdata)
{ {
@ -340,3 +394,152 @@ dctool_file_read (const char *filename)
return buffer; return buffer;
} }
static dc_status_t
dctool_usbhid_open (dc_iostream_t **out, dc_context_t *context, dc_descriptor_t *descriptor)
{
dc_status_t status = DC_STATUS_SUCCESS;
dc_iostream_t *iostream = NULL;
unsigned int vid = 0, pid = 0;
// Discover the usbhid device.
dc_iterator_t *iterator = NULL;
dc_usbhid_device_t *device = NULL;
dc_usbhid_iterator_new (&iterator, context, descriptor);
while (dc_iterator_next (iterator, &device) == DC_STATUS_SUCCESS) {
vid = dc_usbhid_device_get_vid (device);
pid = dc_usbhid_device_get_pid (device);
dc_usbhid_device_free (device);
break;
}
dc_iterator_free (iterator);
if (vid == 0 && pid == 0) {
ERROR ("No dive computer found.");
status = DC_STATUS_NODEVICE;
goto cleanup;
}
// Open the usbhid device.
status = dc_usbhid_open (&iostream, context, vid, pid);
if (status != DC_STATUS_SUCCESS) {
ERROR ("Failed to open the usbhid device.");
goto cleanup;
}
*out = iostream;
cleanup:
return status;
}
static dc_status_t
dctool_irda_open (dc_iostream_t **out, dc_context_t *context, dc_descriptor_t *descriptor, const char *devname)
{
dc_status_t status = DC_STATUS_SUCCESS;
dc_iostream_t *iostream = NULL;
unsigned int address = 0;
if (devname) {
// Use the address.
address = strtoul(devname, NULL, 0);
} else {
// Discover the device address.
dc_iterator_t *iterator = NULL;
dc_irda_device_t *device = NULL;
dc_irda_iterator_new (&iterator, context, descriptor);
while (dc_iterator_next (iterator, &device) == DC_STATUS_SUCCESS) {
address = dc_irda_device_get_address (device);
dc_irda_device_free (device);
break;
}
dc_iterator_free (iterator);
}
if (address == 0) {
if (devname) {
ERROR ("No valid device address specified.");
} else {
ERROR ("No dive computer found.");
}
status = DC_STATUS_NODEVICE;
goto cleanup;
}
// Open the irda socket.
status = dc_irda_open (&iostream, context, address, 1);
if (status != DC_STATUS_SUCCESS) {
ERROR ("Failed to open the irda socket.");
goto cleanup;
}
*out = iostream;
cleanup:
return status;
}
static dc_status_t
dctool_bluetooth_open (dc_iostream_t **out, dc_context_t *context, dc_descriptor_t *descriptor, const char *devname)
{
dc_status_t status = DC_STATUS_SUCCESS;
dc_iostream_t *iostream = NULL;
dc_bluetooth_address_t address = 0;
if (devname) {
// Use the address.
address = dc_bluetooth_str2addr(devname);
} else {
// Discover the device address.
dc_iterator_t *iterator = NULL;
dc_bluetooth_device_t *device = NULL;
dc_bluetooth_iterator_new (&iterator, context, descriptor);
while (dc_iterator_next (iterator, &device) == DC_STATUS_SUCCESS) {
address = dc_bluetooth_device_get_address (device);
dc_bluetooth_device_free (device);
break;
}
dc_iterator_free (iterator);
}
if (address == 0) {
if (devname) {
ERROR ("No valid device address specified.");
} else {
ERROR ("No dive computer found.");
}
status = DC_STATUS_NODEVICE;
goto cleanup;
}
// Open the bluetooth socket.
status = dc_bluetooth_open (&iostream, context, address, 0);
if (status != DC_STATUS_SUCCESS) {
ERROR ("Failed to open the bluetooth socket.");
goto cleanup;
}
*out = iostream;
cleanup:
return status;
}
dc_status_t
dctool_iostream_open (dc_iostream_t **iostream, dc_context_t *context, dc_descriptor_t *descriptor, dc_transport_t transport, const char *devname)
{
switch (transport) {
case DC_TRANSPORT_SERIAL:
return dc_serial_open (iostream, context, devname);
case DC_TRANSPORT_USB:
return DC_STATUS_SUCCESS;
case DC_TRANSPORT_USBHID:
return dctool_usbhid_open(iostream, context, descriptor);
case DC_TRANSPORT_IRDA:
return dctool_irda_open (iostream, context, descriptor, devname);
case DC_TRANSPORT_BLUETOOTH:
return dctool_bluetooth_open (iostream, context, descriptor, devname);
default:
return DC_STATUS_UNSUPPORTED;
}
}

View File

@ -24,6 +24,7 @@
#include <libdivecomputer/context.h> #include <libdivecomputer/context.h>
#include <libdivecomputer/descriptor.h> #include <libdivecomputer/descriptor.h>
#include <libdivecomputer/iostream.h>
#include <libdivecomputer/device.h> #include <libdivecomputer/device.h>
#ifdef __cplusplus #ifdef __cplusplus
@ -42,6 +43,15 @@ dctool_family_name (dc_family_t type);
unsigned int unsigned int
dctool_family_model (dc_family_t type); dctool_family_model (dc_family_t type);
dc_transport_t
dctool_transport_type (const char *name);
const char *
dctool_transport_name (dc_transport_t type);
dc_transport_t
dctool_transport_default (dc_descriptor_t *descriptor);
void void
dctool_event_cb (dc_device_t *device, dc_event_type_t event, const void *data, void *userdata); dctool_event_cb (dc_device_t *device, dc_event_type_t event, const void *data, void *userdata);
@ -57,6 +67,9 @@ dctool_file_write (const char *filename, dc_buffer_t *buffer);
dc_buffer_t * dc_buffer_t *
dctool_file_read (const char *filename); dctool_file_read (const char *filename);
dc_status_t
dctool_iostream_open (dc_iostream_t **iostream, dc_context_t *context, dc_descriptor_t *descriptor, dc_transport_t transport, const char *devname);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif /* __cplusplus */ #endif /* __cplusplus */

View File

@ -58,6 +58,7 @@ static const dctool_command_t *g_commands[] = {
&dctool_help, &dctool_help,
&dctool_version, &dctool_version,
&dctool_list, &dctool_list,
&dctool_scan,
&dctool_download, &dctool_download,
&dctool_dump, &dctool_dump,
&dctool_parse, &dctool_parse,

View File

@ -45,6 +45,7 @@ typedef struct dctool_command_t {
extern const dctool_command_t dctool_help; extern const dctool_command_t dctool_help;
extern const dctool_command_t dctool_version; extern const dctool_command_t dctool_version;
extern const dctool_command_t dctool_list; extern const dctool_command_t dctool_list;
extern const dctool_command_t dctool_scan;
extern const dctool_command_t dctool_download; extern const dctool_command_t dctool_download;
extern const dctool_command_t dctool_dump; extern const dctool_command_t dctool_dump;
extern const dctool_command_t dctool_parse; extern const dctool_command_t dctool_parse;

View File

@ -152,18 +152,28 @@ event_cb (dc_device_t *device, dc_event_type_t event, const void *data, void *us
} }
static dc_status_t static dc_status_t
download (dc_context_t *context, dc_descriptor_t *descriptor, const char *devname, const char *cachedir, dc_buffer_t *fingerprint, dctool_output_t *output) download (dc_context_t *context, dc_descriptor_t *descriptor, dc_transport_t transport, const char *devname, const char *cachedir, dc_buffer_t *fingerprint, dctool_output_t *output)
{ {
dc_status_t rc = DC_STATUS_SUCCESS; dc_status_t rc = DC_STATUS_SUCCESS;
dc_iostream_t *iostream = NULL;
dc_device_t *device = NULL; dc_device_t *device = NULL;
dc_buffer_t *ofingerprint = NULL; dc_buffer_t *ofingerprint = NULL;
// Open the device. // Open the I/O stream.
message ("Opening the device (%s %s, %s).\n", message ("Opening the I/O stream (%s, %s).\n",
dc_descriptor_get_vendor (descriptor), dctool_transport_name (transport),
dc_descriptor_get_product (descriptor),
devname ? devname : "null"); devname ? devname : "null");
rc = dc_device_open (&device, context, descriptor, devname); rc = dctool_iostream_open (&iostream, context, descriptor, transport, devname);
if (rc != DC_STATUS_SUCCESS) {
ERROR ("Error opening the I/O stream.");
goto cleanup;
}
// Open the device.
message ("Opening the device (%s %s).\n",
dc_descriptor_get_vendor (descriptor),
dc_descriptor_get_product (descriptor));
rc = dc_device_open (&device, context, descriptor, iostream);
if (rc != DC_STATUS_SUCCESS) { if (rc != DC_STATUS_SUCCESS) {
ERROR ("Error opening the device."); ERROR ("Error opening the device.");
goto cleanup; goto cleanup;
@ -236,6 +246,7 @@ download (dc_context_t *context, dc_descriptor_t *descriptor, const char *devnam
cleanup: cleanup:
dc_buffer_free (ofingerprint); dc_buffer_free (ofingerprint);
dc_device_close (device); dc_device_close (device);
dc_iostream_close (iostream);
return rc; return rc;
} }
@ -247,6 +258,7 @@ dctool_download_run (int argc, char *argv[], dc_context_t *context, dc_descripto
dc_buffer_t *fingerprint = NULL; dc_buffer_t *fingerprint = NULL;
dctool_output_t *output = NULL; dctool_output_t *output = NULL;
dctool_units_t units = DCTOOL_UNITS_METRIC; dctool_units_t units = DCTOOL_UNITS_METRIC;
dc_transport_t transport = dctool_transport_default (descriptor);
// Default option values. // Default option values.
unsigned int help = 0; unsigned int help = 0;
@ -257,10 +269,11 @@ dctool_download_run (int argc, char *argv[], dc_context_t *context, dc_descripto
// Parse the command-line options. // Parse the command-line options.
int opt = 0; int opt = 0;
const char *optstring = "ho:p:c:f:u:"; const char *optstring = "ht:o:p:c:f:u:";
#ifdef HAVE_GETOPT_LONG #ifdef HAVE_GETOPT_LONG
struct option options[] = { struct option options[] = {
{"help", no_argument, 0, 'h'}, {"help", no_argument, 0, 'h'},
{"transport", required_argument, 0, 't'},
{"output", required_argument, 0, 'o'}, {"output", required_argument, 0, 'o'},
{"fingerprint", required_argument, 0, 'p'}, {"fingerprint", required_argument, 0, 'p'},
{"cache", required_argument, 0, 'c'}, {"cache", required_argument, 0, 'c'},
@ -276,6 +289,9 @@ dctool_download_run (int argc, char *argv[], dc_context_t *context, dc_descripto
case 'h': case 'h':
help = 1; help = 1;
break; break;
case 't':
transport = dctool_transport_type (optarg);
break;
case 'o': case 'o':
filename = optarg; filename = optarg;
break; break;
@ -308,6 +324,13 @@ dctool_download_run (int argc, char *argv[], dc_context_t *context, dc_descripto
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }
// Check the transport type.
if (transport == DC_TRANSPORT_NONE) {
message ("No valid transport type specified.\n");
exitcode = EXIT_FAILURE;
goto cleanup;
}
// Convert the fingerprint to binary. // Convert the fingerprint to binary.
fingerprint = dctool_convert_hex2bin (fphex); fingerprint = dctool_convert_hex2bin (fphex);
@ -328,7 +351,7 @@ dctool_download_run (int argc, char *argv[], dc_context_t *context, dc_descripto
} }
// Download the dives. // Download the dives.
status = download (context, descriptor, argv[0], cachedir, fingerprint, output); status = download (context, descriptor, transport, argv[0], cachedir, fingerprint, output);
if (status != DC_STATUS_SUCCESS) { if (status != DC_STATUS_SUCCESS) {
message ("ERROR: %s\n", dctool_errmsg (status)); message ("ERROR: %s\n", dctool_errmsg (status));
exitcode = EXIT_FAILURE; exitcode = EXIT_FAILURE;
@ -352,6 +375,7 @@ const dctool_command_t dctool_download = {
"Options:\n" "Options:\n"
#ifdef HAVE_GETOPT_LONG #ifdef HAVE_GETOPT_LONG
" -h, --help Show help message\n" " -h, --help Show help message\n"
" -t, --transport <name> Transport type\n"
" -o, --output <filename> Output filename\n" " -o, --output <filename> Output filename\n"
" -p, --fingerprint <data> Fingerprint data (hexadecimal)\n" " -p, --fingerprint <data> Fingerprint data (hexadecimal)\n"
" -c, --cache <directory> Cache directory\n" " -c, --cache <directory> Cache directory\n"
@ -359,6 +383,7 @@ const dctool_command_t dctool_download = {
" -u, --units <units> Set units (metric or imperial)\n" " -u, --units <units> Set units (metric or imperial)\n"
#else #else
" -h Show help message\n" " -h Show help message\n"
" -t <transport> Transport type\n"
" -o <filename> Output filename\n" " -o <filename> Output filename\n"
" -p <fingerprint> Fingerprint data (hexadecimal)\n" " -p <fingerprint> Fingerprint data (hexadecimal)\n"
" -c <directory> Cache directory\n" " -c <directory> Cache directory\n"

View File

@ -40,17 +40,27 @@
#include "utils.h" #include "utils.h"
static dc_status_t static dc_status_t
dump (dc_context_t *context, dc_descriptor_t *descriptor, const char *devname, dc_buffer_t *fingerprint, dc_buffer_t *buffer) dump (dc_context_t *context, dc_descriptor_t *descriptor, dc_transport_t transport, const char *devname, dc_buffer_t *fingerprint, dc_buffer_t *buffer)
{ {
dc_status_t rc = DC_STATUS_SUCCESS; dc_status_t rc = DC_STATUS_SUCCESS;
dc_iostream_t *iostream = NULL;
dc_device_t *device = NULL; dc_device_t *device = NULL;
// Open the device. // Open the I/O stream.
message ("Opening the device (%s %s, %s).\n", message ("Opening the I/O stream (%s, %s).\n",
dc_descriptor_get_vendor (descriptor), dctool_transport_name (transport),
dc_descriptor_get_product (descriptor),
devname ? devname : "null"); devname ? devname : "null");
rc = dc_device_open (&device, context, descriptor, devname); rc = dctool_iostream_open (&iostream, context, descriptor, transport, devname);
if (rc != DC_STATUS_SUCCESS) {
ERROR ("Error opening the I/O stream.");
goto cleanup;
}
// Open the device.
message ("Opening the device (%s %s).\n",
dc_descriptor_get_vendor (descriptor),
dc_descriptor_get_product (descriptor));
rc = dc_device_open (&device, context, descriptor, iostream);
if (rc != DC_STATUS_SUCCESS) { if (rc != DC_STATUS_SUCCESS) {
ERROR ("Error opening the device."); ERROR ("Error opening the device.");
goto cleanup; goto cleanup;
@ -93,6 +103,7 @@ dump (dc_context_t *context, dc_descriptor_t *descriptor, const char *devname, d
cleanup: cleanup:
dc_device_close (device); dc_device_close (device);
dc_iostream_close (iostream);
return rc; return rc;
} }
@ -103,6 +114,7 @@ dctool_dump_run (int argc, char *argv[], dc_context_t *context, dc_descriptor_t
dc_status_t status = DC_STATUS_SUCCESS; dc_status_t status = DC_STATUS_SUCCESS;
dc_buffer_t *fingerprint = NULL; dc_buffer_t *fingerprint = NULL;
dc_buffer_t *buffer = NULL; dc_buffer_t *buffer = NULL;
dc_transport_t transport = dctool_transport_default (descriptor);
// Default option values. // Default option values.
unsigned int help = 0; unsigned int help = 0;
@ -111,10 +123,11 @@ dctool_dump_run (int argc, char *argv[], dc_context_t *context, dc_descriptor_t
// Parse the command-line options. // Parse the command-line options.
int opt = 0; int opt = 0;
const char *optstring = "ho:p:"; const char *optstring = "ht:o:p:";
#ifdef HAVE_GETOPT_LONG #ifdef HAVE_GETOPT_LONG
struct option options[] = { struct option options[] = {
{"help", no_argument, 0, 'h'}, {"help", no_argument, 0, 'h'},
{"transport", required_argument, 0, 't'},
{"output", required_argument, 0, 'o'}, {"output", required_argument, 0, 'o'},
{"fingerprint", required_argument, 0, 'p'}, {"fingerprint", required_argument, 0, 'p'},
{0, 0, 0, 0 } {0, 0, 0, 0 }
@ -127,6 +140,9 @@ dctool_dump_run (int argc, char *argv[], dc_context_t *context, dc_descriptor_t
case 'h': case 'h':
help = 1; help = 1;
break; break;
case 't':
transport = dctool_transport_type (optarg);
break;
case 'o': case 'o':
filename = optarg; filename = optarg;
break; break;
@ -147,6 +163,13 @@ dctool_dump_run (int argc, char *argv[], dc_context_t *context, dc_descriptor_t
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }
// Check the transport type.
if (transport == DC_TRANSPORT_NONE) {
message ("No valid transport type specified.\n");
exitcode = EXIT_FAILURE;
goto cleanup;
}
// Convert the fingerprint to binary. // Convert the fingerprint to binary.
fingerprint = dctool_convert_hex2bin (fphex); fingerprint = dctool_convert_hex2bin (fphex);
@ -154,7 +177,7 @@ dctool_dump_run (int argc, char *argv[], dc_context_t *context, dc_descriptor_t
buffer = dc_buffer_new (0); buffer = dc_buffer_new (0);
// Download the memory dump. // Download the memory dump.
status = dump (context, descriptor, argv[0], fingerprint, buffer); status = dump (context, descriptor, transport, argv[0], fingerprint, buffer);
if (status != DC_STATUS_SUCCESS) { if (status != DC_STATUS_SUCCESS) {
message ("ERROR: %s\n", dctool_errmsg (status)); message ("ERROR: %s\n", dctool_errmsg (status));
exitcode = EXIT_FAILURE; exitcode = EXIT_FAILURE;
@ -181,10 +204,12 @@ const dctool_command_t dctool_dump = {
"Options:\n" "Options:\n"
#ifdef HAVE_GETOPT_LONG #ifdef HAVE_GETOPT_LONG
" -h, --help Show help message\n" " -h, --help Show help message\n"
" -t, --transport <name> Transport type\n"
" -o, --output <filename> Output filename\n" " -o, --output <filename> Output filename\n"
" -p, --fingerprint <data> Fingerprint data (hexadecimal)\n" " -p, --fingerprint <data> Fingerprint data (hexadecimal)\n"
#else #else
" -h Show help message\n" " -h Show help message\n"
" -t <transport> Transport type\n"
" -o <filename> Output filename\n" " -o <filename> Output filename\n"
" -p <fingerprint> Fingerprint data (hexadecimal)\n" " -p <fingerprint> Fingerprint data (hexadecimal)\n"
#endif #endif

View File

@ -41,17 +41,27 @@
#include "utils.h" #include "utils.h"
static dc_status_t static dc_status_t
fwupdate (dc_context_t *context, dc_descriptor_t *descriptor, const char *devname, const char *hexfile) fwupdate (dc_context_t *context, dc_descriptor_t *descriptor, dc_transport_t transport, const char *devname, const char *hexfile)
{ {
dc_status_t rc = DC_STATUS_SUCCESS; dc_status_t rc = DC_STATUS_SUCCESS;
dc_iostream_t *iostream = NULL;
dc_device_t *device = NULL; dc_device_t *device = NULL;
// Open the device. // Open the I/O stream.
message ("Opening the device (%s %s, %s).\n", message ("Opening the I/O stream (%s, %s).\n",
dc_descriptor_get_vendor (descriptor), dctool_transport_name (transport),
dc_descriptor_get_product (descriptor),
devname ? devname : "null"); devname ? devname : "null");
rc = dc_device_open (&device, context, descriptor, devname); rc = dctool_iostream_open (&iostream, context, descriptor, transport, devname);
if (rc != DC_STATUS_SUCCESS) {
ERROR ("Error opening the I/O stream.");
goto cleanup;
}
// Open the device.
message ("Opening the device (%s %s).\n",
dc_descriptor_get_vendor (descriptor),
dc_descriptor_get_product (descriptor));
rc = dc_device_open (&device, context, descriptor, iostream);
if (rc != DC_STATUS_SUCCESS) { if (rc != DC_STATUS_SUCCESS) {
ERROR ("Error opening the device."); ERROR ("Error opening the device.");
goto cleanup; goto cleanup;
@ -94,6 +104,7 @@ fwupdate (dc_context_t *context, dc_descriptor_t *descriptor, const char *devnam
cleanup: cleanup:
dc_device_close (device); dc_device_close (device);
dc_iostream_close (iostream);
return rc; return rc;
} }
@ -102,6 +113,7 @@ dctool_fwupdate_run (int argc, char *argv[], dc_context_t *context, dc_descripto
{ {
int exitcode = EXIT_SUCCESS; int exitcode = EXIT_SUCCESS;
dc_status_t status = DC_STATUS_SUCCESS; dc_status_t status = DC_STATUS_SUCCESS;
dc_transport_t transport = dctool_transport_default (descriptor);
// Default option values. // Default option values.
unsigned int help = 0; unsigned int help = 0;
@ -109,10 +121,11 @@ dctool_fwupdate_run (int argc, char *argv[], dc_context_t *context, dc_descripto
// Parse the command-line options. // Parse the command-line options.
int opt = 0; int opt = 0;
const char *optstring = "hf:"; const char *optstring = "ht:f:";
#ifdef HAVE_GETOPT_LONG #ifdef HAVE_GETOPT_LONG
struct option options[] = { struct option options[] = {
{"help", no_argument, 0, 'h'}, {"help", no_argument, 0, 'h'},
{"transport", required_argument, 0, 't'},
{"firmware", required_argument, 0, 'f'}, {"firmware", required_argument, 0, 'f'},
{0, 0, 0, 0 } {0, 0, 0, 0 }
}; };
@ -124,6 +137,9 @@ dctool_fwupdate_run (int argc, char *argv[], dc_context_t *context, dc_descripto
case 'f': case 'f':
filename = optarg; filename = optarg;
break; break;
case 't':
transport = dctool_transport_type (optarg);
break;
case 'h': case 'h':
help = 1; help = 1;
break; break;
@ -141,6 +157,13 @@ dctool_fwupdate_run (int argc, char *argv[], dc_context_t *context, dc_descripto
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }
// Check the transport type.
if (transport == DC_TRANSPORT_NONE) {
message ("No valid transport type specified.\n");
exitcode = EXIT_FAILURE;
goto cleanup;
}
// Check mandatory arguments. // Check mandatory arguments.
if (!filename) { if (!filename) {
message ("No firmware file specified.\n"); message ("No firmware file specified.\n");
@ -149,7 +172,7 @@ dctool_fwupdate_run (int argc, char *argv[], dc_context_t *context, dc_descripto
} }
// Update the firmware. // Update the firmware.
status = fwupdate (context, descriptor, argv[0], filename); status = fwupdate (context, descriptor, transport, argv[0], filename);
if (status != DC_STATUS_SUCCESS) { if (status != DC_STATUS_SUCCESS) {
message ("ERROR: %s\n", dctool_errmsg (status)); message ("ERROR: %s\n", dctool_errmsg (status));
exitcode = EXIT_FAILURE; exitcode = EXIT_FAILURE;
@ -171,9 +194,11 @@ const dctool_command_t dctool_fwupdate = {
"Options:\n" "Options:\n"
#ifdef HAVE_GETOPT_LONG #ifdef HAVE_GETOPT_LONG
" -h, --help Show help message\n" " -h, --help Show help message\n"
" -t, --transport <name> Transport type\n"
" -f, --firmware <filename> Firmware filename\n" " -f, --firmware <filename> Firmware filename\n"
#else #else
" -h Show help message\n" " -h Show help message\n"
" -t <transport> Transport type\n"
" -f <filename> Firmware filename\n" " -f <filename> Firmware filename\n"
#endif #endif
}; };

View File

@ -39,17 +39,27 @@
#include "utils.h" #include "utils.h"
static dc_status_t static dc_status_t
doread (dc_context_t *context, dc_descriptor_t *descriptor, const char *devname, unsigned int address, dc_buffer_t *buffer) doread (dc_context_t *context, dc_descriptor_t *descriptor, dc_transport_t transport, const char *devname, unsigned int address, dc_buffer_t *buffer)
{ {
dc_status_t rc = DC_STATUS_SUCCESS; dc_status_t rc = DC_STATUS_SUCCESS;
dc_iostream_t *iostream = NULL;
dc_device_t *device = NULL; dc_device_t *device = NULL;
// Open the device. // Open the I/O stream.
message ("Opening the device (%s %s, %s).\n", message ("Opening the I/O stream (%s, %s).\n",
dc_descriptor_get_vendor (descriptor), dctool_transport_name (transport),
dc_descriptor_get_product (descriptor),
devname ? devname : "null"); devname ? devname : "null");
rc = dc_device_open (&device, context, descriptor, devname); rc = dctool_iostream_open (&iostream, context, descriptor, transport, devname);
if (rc != DC_STATUS_SUCCESS) {
ERROR ("Error opening the I/O stream.");
goto cleanup;
}
// Open the device.
message ("Opening the device (%s %s).\n",
dc_descriptor_get_vendor (descriptor),
dc_descriptor_get_product (descriptor));
rc = dc_device_open (&device, context, descriptor, iostream);
if (rc != DC_STATUS_SUCCESS) { if (rc != DC_STATUS_SUCCESS) {
ERROR ("Error opening the device."); ERROR ("Error opening the device.");
goto cleanup; goto cleanup;
@ -82,6 +92,7 @@ doread (dc_context_t *context, dc_descriptor_t *descriptor, const char *devname,
cleanup: cleanup:
dc_device_close (device); dc_device_close (device);
dc_iostream_close (iostream);
return rc; return rc;
} }
@ -91,6 +102,7 @@ dctool_read_run (int argc, char *argv[], dc_context_t *context, dc_descriptor_t
int exitcode = EXIT_SUCCESS; int exitcode = EXIT_SUCCESS;
dc_status_t status = DC_STATUS_SUCCESS; dc_status_t status = DC_STATUS_SUCCESS;
dc_buffer_t *buffer = NULL; dc_buffer_t *buffer = NULL;
dc_transport_t transport = dctool_transport_default (descriptor);
// Default option values. // Default option values.
unsigned int help = 0; unsigned int help = 0;
@ -100,10 +112,11 @@ dctool_read_run (int argc, char *argv[], dc_context_t *context, dc_descriptor_t
// Parse the command-line options. // Parse the command-line options.
int opt = 0; int opt = 0;
const char *optstring = "ha:c:o:"; const char *optstring = "ht:a:c:o:";
#ifdef HAVE_GETOPT_LONG #ifdef HAVE_GETOPT_LONG
struct option options[] = { struct option options[] = {
{"help", no_argument, 0, 'h'}, {"help", no_argument, 0, 'h'},
{"transport", required_argument, 0, 't'},
{"address", required_argument, 0, 'a'}, {"address", required_argument, 0, 'a'},
{"count", required_argument, 0, 'c'}, {"count", required_argument, 0, 'c'},
{"output", required_argument, 0, 'o'}, {"output", required_argument, 0, 'o'},
@ -117,6 +130,9 @@ dctool_read_run (int argc, char *argv[], dc_context_t *context, dc_descriptor_t
case 'h': case 'h':
help = 1; help = 1;
break; break;
case 't':
transport = dctool_transport_type (optarg);
break;
case 'a': case 'a':
address = strtoul (optarg, NULL, 0); address = strtoul (optarg, NULL, 0);
have_address = 1; have_address = 1;
@ -142,6 +158,13 @@ dctool_read_run (int argc, char *argv[], dc_context_t *context, dc_descriptor_t
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }
// Check the transport type.
if (transport == DC_TRANSPORT_NONE) {
message ("No valid transport type specified.\n");
exitcode = EXIT_FAILURE;
goto cleanup;
}
// Check mandatory arguments. // Check mandatory arguments.
if (!have_address || !have_count) { if (!have_address || !have_count) {
message ("No memory address or byte count specified.\n"); message ("No memory address or byte count specified.\n");
@ -159,7 +182,7 @@ dctool_read_run (int argc, char *argv[], dc_context_t *context, dc_descriptor_t
} }
// Read data from the internal memory. // Read data from the internal memory.
status = doread (context, descriptor, argv[0], address, buffer); status = doread (context, descriptor, transport, argv[0], address, buffer);
if (status != DC_STATUS_SUCCESS) { if (status != DC_STATUS_SUCCESS) {
message ("ERROR: %s\n", dctool_errmsg (status)); message ("ERROR: %s\n", dctool_errmsg (status));
exitcode = EXIT_FAILURE; exitcode = EXIT_FAILURE;
@ -185,11 +208,13 @@ const dctool_command_t dctool_read = {
"Options:\n" "Options:\n"
#ifdef HAVE_GETOPT_LONG #ifdef HAVE_GETOPT_LONG
" -h, --help Show help message\n" " -h, --help Show help message\n"
" -t, --transport <name> Transport type\n"
" -a, --address <address> Memory address\n" " -a, --address <address> Memory address\n"
" -c, --count <count> Number of bytes\n" " -c, --count <count> Number of bytes\n"
" -o, --output <filename> Output filename\n" " -o, --output <filename> Output filename\n"
#else #else
" -h Show help message\n" " -h Show help message\n"
" -t <transport> Transport type\n"
" -a <address> Memory address\n" " -a <address> Memory address\n"
" -c <count> Number of bytes\n" " -c <count> Number of bytes\n"
" -o <filename> Output filename\n" " -o <filename> Output filename\n"

192
examples/dctool_scan.c Normal file
View File

@ -0,0 +1,192 @@
/*
* libdivecomputer
*
* Copyright (C) 2017 Jef Driesen
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
#ifdef HAVE_GETOPT_H
#include <getopt.h>
#endif
#include <libdivecomputer/context.h>
#include <libdivecomputer/descriptor.h>
#include <libdivecomputer/iterator.h>
#include <libdivecomputer/serial.h>
#include <libdivecomputer/irda.h>
#include <libdivecomputer/bluetooth.h>
#include <libdivecomputer/usbhid.h>
#include "dctool.h"
#include "common.h"
#include "utils.h"
static dc_status_t
scan (dc_context_t *context, dc_descriptor_t *descriptor, dc_transport_t transport)
{
dc_status_t status = DC_STATUS_SUCCESS;
dc_iterator_t *iterator = NULL;
// Create the device iterator.
switch (transport) {
case DC_TRANSPORT_SERIAL:
status = dc_serial_iterator_new (&iterator, context, descriptor);
break;
case DC_TRANSPORT_IRDA:
status = dc_irda_iterator_new (&iterator, context, descriptor);
break;
case DC_TRANSPORT_BLUETOOTH:
status = dc_bluetooth_iterator_new (&iterator, context, descriptor);
break;
case DC_TRANSPORT_USBHID:
status = dc_usbhid_iterator_new (&iterator, context, descriptor);
break;
default:
status = DC_STATUS_UNSUPPORTED;
break;
}
if (status != DC_STATUS_SUCCESS) {
ERROR ("Failed to create the device iterator.");
goto cleanup;
}
// Enumerate the devices.
void *device = NULL;
while ((status = dc_iterator_next (iterator, &device)) == DC_STATUS_SUCCESS) {
char buffer[DC_BLUETOOTH_SIZE];
switch (transport) {
case DC_TRANSPORT_SERIAL:
printf ("%s\n", dc_serial_device_get_name (device));
dc_serial_device_free (device);
break;
case DC_TRANSPORT_IRDA:
printf ("%08x\t%s\n", dc_irda_device_get_address (device), dc_irda_device_get_name (device));
dc_irda_device_free (device);
break;
case DC_TRANSPORT_BLUETOOTH:
printf ("%s\t%s\n",
dc_bluetooth_addr2str(dc_bluetooth_device_get_address (device), buffer, sizeof(buffer)),
dc_bluetooth_device_get_name (device));
dc_bluetooth_device_free (device);
break;
case DC_TRANSPORT_USBHID:
printf ("%04x:%04x\n", dc_usbhid_device_get_vid (device), dc_usbhid_device_get_pid (device));
dc_usbhid_device_free (device);
break;
default:
break;
}
}
if (status != DC_STATUS_SUCCESS && status != DC_STATUS_DONE) {
ERROR ("Failed to enumerate the devices.");
goto cleanup;
}
status = DC_STATUS_SUCCESS;
cleanup:
dc_iterator_free (iterator);
return status;
}
static int
dctool_scan_run (int argc, char *argv[], dc_context_t *context, dc_descriptor_t *descriptor)
{
int exitcode = EXIT_SUCCESS;
dc_status_t status = DC_STATUS_SUCCESS;
// Default option values.
unsigned int help = 0;
dc_transport_t transport = dctool_transport_default (descriptor);
// Parse the command-line options.
int opt = 0;
const char *optstring = "ht:";
#ifdef HAVE_GETOPT_LONG
struct option options[] = {
{"help", no_argument, 0, 'h'},
{"transport", required_argument, 0, 't'},
{0, 0, 0, 0 }
};
while ((opt = getopt_long (argc, argv, optstring, options, NULL)) != -1) {
#else
while ((opt = getopt (argc, argv, optstring)) != -1) {
#endif
switch (opt) {
case 'h':
help = 1;
break;
case 't':
transport = dctool_transport_type (optarg);
break;
default:
return EXIT_FAILURE;
}
}
argc -= optind;
argv += optind;
// Show help message.
if (help) {
dctool_command_showhelp (&dctool_list);
return EXIT_SUCCESS;
}
// Check the transport type.
if (transport == DC_TRANSPORT_NONE) {
message ("No valid transport type specified.\n");
exitcode = EXIT_FAILURE;
goto cleanup;
}
// Scan for supported devices.
status = scan (context, descriptor, transport);
if (status != DC_STATUS_SUCCESS) {
message ("ERROR: %s\n", dctool_errmsg (status));
exitcode = EXIT_FAILURE;
goto cleanup;
}
cleanup:
return exitcode;
}
const dctool_command_t dctool_scan = {
dctool_scan_run,
DCTOOL_CONFIG_NONE,
"scan",
"Scan for supported devices",
"Usage:\n"
" dctool scan [options]\n"
"\n"
"Options:\n"
#ifdef HAVE_GETOPT_LONG
" -h, --help Show help message\n"
" -t, --transport <name> Transport type\n"
#else
" -h Show help message\n"
" -t <transport> Transport type\n"
#endif
};

View File

@ -39,17 +39,27 @@
#include "utils.h" #include "utils.h"
static dc_status_t static dc_status_t
do_timesync (dc_context_t *context, dc_descriptor_t *descriptor, const char *devname, const dc_datetime_t *datetime) do_timesync (dc_context_t *context, dc_descriptor_t *descriptor, dc_transport_t transport, const char *devname, const dc_datetime_t *datetime)
{ {
dc_status_t rc = DC_STATUS_SUCCESS; dc_status_t rc = DC_STATUS_SUCCESS;
dc_iostream_t *iostream = NULL;
dc_device_t *device = NULL; dc_device_t *device = NULL;
// Open the device. // Open the I/O stream.
message ("Opening the device (%s %s, %s).\n", message ("Opening the I/O stream (%s, %s).\n",
dc_descriptor_get_vendor (descriptor), dctool_transport_name (transport),
dc_descriptor_get_product (descriptor),
devname ? devname : "null"); devname ? devname : "null");
rc = dc_device_open (&device, context, descriptor, devname); rc = dctool_iostream_open (&iostream, context, descriptor, transport, devname);
if (rc != DC_STATUS_SUCCESS) {
ERROR ("Error opening the I/O stream.");
goto cleanup;
}
// Open the device.
message ("Opening the device (%s %s).\n",
dc_descriptor_get_vendor (descriptor),
dc_descriptor_get_product (descriptor));
rc = dc_device_open (&device, context, descriptor, iostream);
if (rc != DC_STATUS_SUCCESS) { if (rc != DC_STATUS_SUCCESS) {
ERROR ("Error opening the device."); ERROR ("Error opening the device.");
goto cleanup; goto cleanup;
@ -82,6 +92,7 @@ do_timesync (dc_context_t *context, dc_descriptor_t *descriptor, const char *dev
cleanup: cleanup:
dc_device_close (device); dc_device_close (device);
dc_iostream_close (iostream);
return rc; return rc;
} }
@ -90,16 +101,18 @@ dctool_timesync_run (int argc, char *argv[], dc_context_t *context, dc_descripto
{ {
int exitcode = EXIT_SUCCESS; int exitcode = EXIT_SUCCESS;
dc_status_t status = DC_STATUS_SUCCESS; dc_status_t status = DC_STATUS_SUCCESS;
dc_transport_t transport = dctool_transport_default (descriptor);
// Default option values. // Default option values.
unsigned int help = 0; unsigned int help = 0;
// Parse the command-line options. // Parse the command-line options.
int opt = 0; int opt = 0;
const char *optstring = "h"; const char *optstring = "ht:";
#ifdef HAVE_GETOPT_LONG #ifdef HAVE_GETOPT_LONG
struct option options[] = { struct option options[] = {
{"help", no_argument, 0, 'h'}, {"help", no_argument, 0, 'h'},
{"transport", required_argument, 0, 't'},
{0, 0, 0, 0 } {0, 0, 0, 0 }
}; };
while ((opt = getopt_long (argc, argv, optstring, options, NULL)) != -1) { while ((opt = getopt_long (argc, argv, optstring, options, NULL)) != -1) {
@ -124,6 +137,13 @@ dctool_timesync_run (int argc, char *argv[], dc_context_t *context, dc_descripto
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }
// Check the transport type.
if (transport == DC_TRANSPORT_NONE) {
message ("No valid transport type specified.\n");
exitcode = EXIT_FAILURE;
goto cleanup;
}
// Get the system time. // Get the system time.
dc_datetime_t datetime = {0}; dc_datetime_t datetime = {0};
dc_ticks_t now = dc_datetime_now (); dc_ticks_t now = dc_datetime_now ();
@ -134,7 +154,7 @@ dctool_timesync_run (int argc, char *argv[], dc_context_t *context, dc_descripto
} }
// Synchronize the device clock. // Synchronize the device clock.
status = do_timesync (context, descriptor, argv[0], &datetime); status = do_timesync (context, descriptor, transport, argv[0], &datetime);
if (status != DC_STATUS_SUCCESS) { if (status != DC_STATUS_SUCCESS) {
message ("ERROR: %s\n", dctool_errmsg (status)); message ("ERROR: %s\n", dctool_errmsg (status));
exitcode = EXIT_FAILURE; exitcode = EXIT_FAILURE;
@ -155,8 +175,10 @@ const dctool_command_t dctool_timesync = {
"\n" "\n"
"Options:\n" "Options:\n"
#ifdef HAVE_GETOPT_LONG #ifdef HAVE_GETOPT_LONG
" -h, --help Show help message\n" " -h, --help Show help message\n"
" -t, --transport <name> Transport type\n"
#else #else
" -h Show help message\n" " -h Show help message\n"
" -t <transport> Transport type\n"
#endif #endif
}; };

View File

@ -39,17 +39,27 @@
#include "utils.h" #include "utils.h"
static dc_status_t static dc_status_t
dowrite (dc_context_t *context, dc_descriptor_t *descriptor, const char *devname, unsigned int address, dc_buffer_t *buffer) dowrite (dc_context_t *context, dc_descriptor_t *descriptor, dc_transport_t transport, const char *devname, unsigned int address, dc_buffer_t *buffer)
{ {
dc_status_t rc = DC_STATUS_SUCCESS; dc_status_t rc = DC_STATUS_SUCCESS;
dc_iostream_t *iostream = NULL;
dc_device_t *device = NULL; dc_device_t *device = NULL;
// Open the device. // Open the I/O stream.
message ("Opening the device (%s %s, %s).\n", message ("Opening the I/O stream (%s, %s).\n",
dc_descriptor_get_vendor (descriptor), dctool_transport_name (transport),
dc_descriptor_get_product (descriptor),
devname ? devname : "null"); devname ? devname : "null");
rc = dc_device_open (&device, context, descriptor, devname); rc = dctool_iostream_open (&iostream, context, descriptor, transport, devname);
if (rc != DC_STATUS_SUCCESS) {
ERROR ("Error opening the I/O stream.");
goto cleanup;
}
// Open the device.
message ("Opening the device (%s %s).\n",
dc_descriptor_get_vendor (descriptor),
dc_descriptor_get_product (descriptor));
rc = dc_device_open (&device, context, descriptor, iostream);
if (rc != DC_STATUS_SUCCESS) { if (rc != DC_STATUS_SUCCESS) {
ERROR ("Error opening the device."); ERROR ("Error opening the device.");
goto cleanup; goto cleanup;
@ -82,6 +92,7 @@ dowrite (dc_context_t *context, dc_descriptor_t *descriptor, const char *devname
cleanup: cleanup:
dc_device_close (device); dc_device_close (device);
dc_iostream_close (iostream);
return rc; return rc;
} }
@ -91,6 +102,7 @@ dctool_write_run (int argc, char *argv[], dc_context_t *context, dc_descriptor_t
int exitcode = EXIT_SUCCESS; int exitcode = EXIT_SUCCESS;
dc_status_t status = DC_STATUS_SUCCESS; dc_status_t status = DC_STATUS_SUCCESS;
dc_buffer_t *buffer = NULL; dc_buffer_t *buffer = NULL;
dc_transport_t transport = dctool_transport_default (descriptor);
// Default option values. // Default option values.
unsigned int help = 0; unsigned int help = 0;
@ -100,10 +112,11 @@ dctool_write_run (int argc, char *argv[], dc_context_t *context, dc_descriptor_t
// Parse the command-line options. // Parse the command-line options.
int opt = 0; int opt = 0;
const char *optstring = "ha:c:i:"; const char *optstring = "ht:a:c:i:";
#ifdef HAVE_GETOPT_LONG #ifdef HAVE_GETOPT_LONG
struct option options[] = { struct option options[] = {
{"help", no_argument, 0, 'h'}, {"help", no_argument, 0, 'h'},
{"transport", required_argument, 0, 't'},
{"address", required_argument, 0, 'a'}, {"address", required_argument, 0, 'a'},
{"count", required_argument, 0, 'c'}, {"count", required_argument, 0, 'c'},
{"input", required_argument, 0, 'i'}, {"input", required_argument, 0, 'i'},
@ -117,6 +130,9 @@ dctool_write_run (int argc, char *argv[], dc_context_t *context, dc_descriptor_t
case 'h': case 'h':
help = 1; help = 1;
break; break;
case 't':
transport = dctool_transport_type (optarg);
break;
case 'a': case 'a':
address = strtoul (optarg, NULL, 0); address = strtoul (optarg, NULL, 0);
have_address = 1; have_address = 1;
@ -142,6 +158,13 @@ dctool_write_run (int argc, char *argv[], dc_context_t *context, dc_descriptor_t
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }
// Check the transport type.
if (transport == DC_TRANSPORT_NONE) {
message ("No valid transport type specified.\n");
exitcode = EXIT_FAILURE;
goto cleanup;
}
// Check mandatory arguments. // Check mandatory arguments.
if (!have_address) { if (!have_address) {
message ("No memory address specified.\n"); message ("No memory address specified.\n");
@ -165,7 +188,7 @@ dctool_write_run (int argc, char *argv[], dc_context_t *context, dc_descriptor_t
} }
// Write data to the internal memory. // Write data to the internal memory.
status = dowrite (context, descriptor, argv[0], address, buffer); status = dowrite (context, descriptor, transport, argv[0], address, buffer);
if (status != DC_STATUS_SUCCESS) { if (status != DC_STATUS_SUCCESS) {
message ("ERROR: %s\n", dctool_errmsg (status)); message ("ERROR: %s\n", dctool_errmsg (status));
exitcode = EXIT_FAILURE; exitcode = EXIT_FAILURE;
@ -188,11 +211,13 @@ const dctool_command_t dctool_write = {
"Options:\n" "Options:\n"
#ifdef HAVE_GETOPT_LONG #ifdef HAVE_GETOPT_LONG
" -h, --help Show help message\n" " -h, --help Show help message\n"
" -t, --transport <name> Transport type\n"
" -a, --address <address> Memory address\n" " -a, --address <address> Memory address\n"
" -c, --count <count> Number of bytes\n" " -c, --count <count> Number of bytes\n"
" -i, --input <filename> Input filename\n" " -i, --input <filename> Input filename\n"
#else #else
" -h Show help message\n" " -h Show help message\n"
" -t <transport> Transport type\n"
" -a <address> Memory address\n" " -a <address> Memory address\n"
" -c <count> Number of bytes\n" " -c <count> Number of bytes\n"
" -i <filename> Input filename\n" " -i <filename> Input filename\n"

View File

@ -7,6 +7,11 @@ libdivecomputer_HEADERS = \
descriptor.h \ descriptor.h \
iterator.h \ iterator.h \
iostream.h \ iostream.h \
serial.h \
bluetooth.h \
irda.h \
usbhid.h \
custom.h \
device.h \ device.h \
parser.h \ parser.h \
datetime.h \ datetime.h \

View File

@ -22,11 +22,11 @@
#ifndef DC_BLUETOOTH_H #ifndef DC_BLUETOOTH_H
#define DC_BLUETOOTH_H #define DC_BLUETOOTH_H
#include <libdivecomputer/common.h> #include "common.h"
#include <libdivecomputer/context.h> #include "context.h"
#include <libdivecomputer/iostream.h> #include "iostream.h"
#include <libdivecomputer/iterator.h> #include "iterator.h"
#include <libdivecomputer/descriptor.h> #include "descriptor.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {

View File

@ -41,6 +41,15 @@ typedef enum dc_status_t {
DC_STATUS_CANCELLED = -10 DC_STATUS_CANCELLED = -10
} dc_status_t; } dc_status_t;
typedef enum dc_transport_t {
DC_TRANSPORT_NONE = 0,
DC_TRANSPORT_SERIAL = (1 << 0),
DC_TRANSPORT_USB = (1 << 1),
DC_TRANSPORT_USBHID = (1 << 2),
DC_TRANSPORT_IRDA = (1 << 3),
DC_TRANSPORT_BLUETOOTH = (1 << 4),
} dc_transport_t;
typedef enum dc_family_t { typedef enum dc_family_t {
DC_FAMILY_NULL = 0, DC_FAMILY_NULL = 0,
/* Suunto */ /* Suunto */

View File

@ -53,6 +53,9 @@ dc_context_set_loglevel (dc_context_t *context, dc_loglevel_t loglevel);
dc_status_t dc_status_t
dc_context_set_logfunc (dc_context_t *context, dc_logfunc_t logfunc, void *userdata); dc_context_set_logfunc (dc_context_t *context, dc_logfunc_t logfunc, void *userdata);
unsigned int
dc_context_get_transports (dc_context_t *context);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif /* __cplusplus */ #endif /* __cplusplus */

View File

@ -22,9 +22,9 @@
#ifndef DC_CUSTOM_H #ifndef DC_CUSTOM_H
#define DC_CUSTOM_H #define DC_CUSTOM_H
#include <libdivecomputer/common.h> #include "common.h"
#include <libdivecomputer/context.h> #include "context.h"
#include <libdivecomputer/iostream.h> #include "iostream.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
@ -58,7 +58,7 @@ typedef struct dc_custom_cbs_t {
* on failure. * on failure.
*/ */
dc_status_t dc_status_t
dc_custom_open (dc_iostream_t **iostream, dc_context_t *context, const dc_custom_cbs_t *callbacks, void *userdata); dc_custom_open (dc_iostream_t **iostream, dc_context_t *context, dc_transport_t transport, const dc_custom_cbs_t *callbacks, void *userdata);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -29,15 +29,6 @@
extern "C" { extern "C" {
#endif /* __cplusplus */ #endif /* __cplusplus */
typedef enum dc_transport_t {
DC_TRANSPORT_NONE,
DC_TRANSPORT_SERIAL,
DC_TRANSPORT_USB,
DC_TRANSPORT_USBHID,
DC_TRANSPORT_IRDA,
DC_TRANSPORT_BLUETOOTH
} dc_transport_t;
typedef struct dc_descriptor_t dc_descriptor_t; typedef struct dc_descriptor_t dc_descriptor_t;
dc_status_t dc_status_t
@ -58,8 +49,8 @@ dc_descriptor_get_type (dc_descriptor_t *descriptor);
unsigned int unsigned int
dc_descriptor_get_model (dc_descriptor_t *descriptor); dc_descriptor_get_model (dc_descriptor_t *descriptor);
dc_transport_t unsigned int
dc_descriptor_get_transport (dc_descriptor_t *descriptor); dc_descriptor_get_transports (dc_descriptor_t *descriptor);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -25,6 +25,7 @@
#include "common.h" #include "common.h"
#include "context.h" #include "context.h"
#include "descriptor.h" #include "descriptor.h"
#include "iostream.h"
#include "buffer.h" #include "buffer.h"
#include "datetime.h" #include "datetime.h"
@ -70,7 +71,7 @@ typedef void (*dc_event_callback_t) (dc_device_t *device, dc_event_type_t event,
typedef int (*dc_dive_callback_t) (const unsigned char *data, unsigned int size, const unsigned char *fingerprint, unsigned int fsize, void *userdata); typedef int (*dc_dive_callback_t) (const unsigned char *data, unsigned int size, const unsigned char *fingerprint, unsigned int fsize, void *userdata);
dc_status_t dc_status_t
dc_device_open (dc_device_t **out, dc_context_t *context, dc_descriptor_t *descriptor, const char *name); dc_device_open (dc_device_t **out, dc_context_t *context, dc_descriptor_t *descriptor, dc_iostream_t *iostream);
dc_family_t dc_family_t
dc_device_get_type (dc_device_t *device); dc_device_get_type (dc_device_t *device);

View File

@ -82,6 +82,15 @@ typedef enum dc_line_t {
DC_LINE_RNG = 0x08, /**< Ring indicator */ DC_LINE_RNG = 0x08, /**< Ring indicator */
} dc_line_t; } dc_line_t;
/**
* Get the transport type.
*
* @param[in] iostream A valid I/O stream.
* @returns The transport type of the I/O stream.
*/
dc_transport_t
dc_iostream_get_transport (dc_iostream_t *iostream);
/** /**
* Set the read timeout. * Set the read timeout.
* *

View File

@ -22,11 +22,11 @@
#ifndef DC_IRDA_H #ifndef DC_IRDA_H
#define DC_IRDA_H #define DC_IRDA_H
#include <libdivecomputer/common.h> #include "common.h"
#include <libdivecomputer/context.h> #include "context.h"
#include <libdivecomputer/iostream.h> #include "iostream.h"
#include <libdivecomputer/iterator.h> #include "iterator.h"
#include <libdivecomputer/descriptor.h> #include "descriptor.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {

View File

@ -22,11 +22,11 @@
#ifndef DC_SERIAL_H #ifndef DC_SERIAL_H
#define DC_SERIAL_H #define DC_SERIAL_H
#include <libdivecomputer/common.h> #include "common.h"
#include <libdivecomputer/context.h> #include "context.h"
#include <libdivecomputer/iostream.h> #include "iostream.h"
#include <libdivecomputer/iterator.h> #include "iterator.h"
#include <libdivecomputer/descriptor.h> #include "descriptor.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {

View File

@ -22,11 +22,11 @@
#ifndef DC_USBHID_H #ifndef DC_USBHID_H
#define DC_USBHID_H #define DC_USBHID_H
#include <libdivecomputer/common.h> #include "common.h"
#include <libdivecomputer/context.h> #include "context.h"
#include <libdivecomputer/iostream.h> #include "iostream.h"
#include <libdivecomputer/iterator.h> #include "iterator.h"
#include <libdivecomputer/descriptor.h> #include "descriptor.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {

View File

@ -549,7 +549,7 @@
> >
</File> </File>
<File <File
RelativePath="..\src\bluetooth.h" RelativePath="..\include\libdivecomputer\bluetooth.h"
> >
</File> </File>
<File <File
@ -589,7 +589,7 @@
> >
</File> </File>
<File <File
RelativePath="..\src\custom.h" RelativePath="..\include\libdivecomputer\custom.h"
> >
</File> </File>
<File <File
@ -653,7 +653,7 @@
> >
</File> </File>
<File <File
RelativePath="..\src\irda.h" RelativePath="..\include\libdivecomputer\irda.h"
> >
</File> </File>
<File <File
@ -761,7 +761,7 @@
> >
</File> </File>
<File <File
RelativePath="..\src\serial.h" RelativePath="..\include\libdivecomputer\serial.h"
> >
</File> </File>
<File <File
@ -833,7 +833,7 @@
> >
</File> </File>
<File <File
RelativePath="..\src\usbhid.h" RelativePath="..\include\libdivecomputer\usbhid.h"
> >
</File> </File>
<File <File

View File

@ -71,20 +71,19 @@ libdivecomputer_la_SOURCES = \
checksum.h checksum.c \ checksum.h checksum.c \
array.h array.c \ array.h array.c \
buffer.c \ buffer.c \
cochran_commander.h cochran_commander.c cochran_commander_parser.c cochran_commander.h cochran_commander.c cochran_commander_parser.c \
socket.h socket.c \
irda.c \
usbhid.c \
bluetooth.c \
custom.c
if OS_WIN32 if OS_WIN32
libdivecomputer_la_SOURCES += serial.h serial_win32.c libdivecomputer_la_SOURCES += serial_win32.c
else else
libdivecomputer_la_SOURCES += serial.h serial_posix.c libdivecomputer_la_SOURCES += serial_posix.c
endif endif
libdivecomputer_la_SOURCES += socket.h socket.c
libdivecomputer_la_SOURCES += irda.h irda.c
libdivecomputer_la_SOURCES += usbhid.h usbhid.c
libdivecomputer_la_SOURCES += bluetooth.h bluetooth.c
libdivecomputer_la_SOURCES += custom.h custom.c
if OS_WIN32 if OS_WIN32
libdivecomputer_la_SOURCES += libdivecomputer.rc libdivecomputer_la_SOURCES += libdivecomputer.rc
endif endif

View File

@ -46,7 +46,7 @@
#endif #endif
#endif #endif
#include "bluetooth.h" #include <libdivecomputer/bluetooth.h>
#include "common-private.h" #include "common-private.h"
#include "context-private.h" #include "context-private.h"
@ -504,7 +504,7 @@ dc_bluetooth_open (dc_iostream_t **out, dc_context_t *context, dc_bluetooth_addr
INFO (context, "Open: address=" DC_ADDRESS_FORMAT ", port=%u", address, port); INFO (context, "Open: address=" DC_ADDRESS_FORMAT ", port=%u", address, port);
// Allocate memory. // Allocate memory.
device = (dc_socket_t *) dc_iostream_allocate (context, &dc_bluetooth_vtable); device = (dc_socket_t *) dc_iostream_allocate (context, &dc_bluetooth_vtable, DC_TRANSPORT_BLUETOOTH);
if (device == NULL) { if (device == NULL) {
SYSERROR (context, S_ENOMEM); SYSERROR (context, S_ENOMEM);
return DC_STATUS_NOMEMORY; return DC_STATUS_NOMEMORY;

View File

@ -25,7 +25,6 @@
#include "citizen_aqualand.h" #include "citizen_aqualand.h"
#include "context-private.h" #include "context-private.h"
#include "device-private.h" #include "device-private.h"
#include "serial.h"
#include "checksum.h" #include "checksum.h"
#include "ringbuffer.h" #include "ringbuffer.h"
#include "array.h" #include "array.h"
@ -41,7 +40,6 @@ typedef struct citizen_aqualand_device_t {
static dc_status_t citizen_aqualand_device_set_fingerprint (dc_device_t *abstract, const unsigned char data[], unsigned int size); static dc_status_t citizen_aqualand_device_set_fingerprint (dc_device_t *abstract, const unsigned char data[], unsigned int size);
static dc_status_t citizen_aqualand_device_dump (dc_device_t *abstract, dc_buffer_t *buffer); static dc_status_t citizen_aqualand_device_dump (dc_device_t *abstract, dc_buffer_t *buffer);
static dc_status_t citizen_aqualand_device_foreach (dc_device_t *abstract, dc_dive_callback_t callback, void *userdata); static dc_status_t citizen_aqualand_device_foreach (dc_device_t *abstract, dc_dive_callback_t callback, void *userdata);
static dc_status_t citizen_aqualand_device_close (dc_device_t *abstract);
static const dc_device_vtable_t citizen_aqualand_device_vtable = { static const dc_device_vtable_t citizen_aqualand_device_vtable = {
sizeof(citizen_aqualand_device_t), sizeof(citizen_aqualand_device_t),
@ -52,12 +50,12 @@ static const dc_device_vtable_t citizen_aqualand_device_vtable = {
citizen_aqualand_device_dump, /* dump */ citizen_aqualand_device_dump, /* dump */
citizen_aqualand_device_foreach, /* foreach */ citizen_aqualand_device_foreach, /* foreach */
NULL, /* timesync */ NULL, /* timesync */
citizen_aqualand_device_close /* close */ NULL /* close */
}; };
dc_status_t dc_status_t
citizen_aqualand_device_open (dc_device_t **out, dc_context_t *context, const char *name) citizen_aqualand_device_open (dc_device_t **out, dc_context_t *context, dc_iostream_t *iostream)
{ {
dc_status_t status = DC_STATUS_SUCCESS; dc_status_t status = DC_STATUS_SUCCESS;
citizen_aqualand_device_t *device = NULL; citizen_aqualand_device_t *device = NULL;
@ -73,28 +71,21 @@ citizen_aqualand_device_open (dc_device_t **out, dc_context_t *context, const ch
} }
// Set the default values. // Set the default values.
device->iostream = NULL; device->iostream = iostream;
memset (device->fingerprint, 0, sizeof (device->fingerprint)); memset (device->fingerprint, 0, sizeof (device->fingerprint));
// Open the device.
status = dc_serial_open (&device->iostream, context, name);
if (status != DC_STATUS_SUCCESS) {
ERROR (context, "Failed to open the serial port.");
goto error_free;
}
// Set the serial communication protocol (4800 8N1). // Set the serial communication protocol (4800 8N1).
status = dc_iostream_configure (device->iostream, 4800, 8, DC_PARITY_NONE, DC_STOPBITS_ONE, DC_FLOWCONTROL_NONE); status = dc_iostream_configure (device->iostream, 4800, 8, DC_PARITY_NONE, DC_STOPBITS_ONE, DC_FLOWCONTROL_NONE);
if (status != DC_STATUS_SUCCESS) { if (status != DC_STATUS_SUCCESS) {
ERROR (context, "Failed to set the terminal attributes."); ERROR (context, "Failed to set the terminal attributes.");
goto error_close; goto error_free;
} }
// Set the timeout for receiving data (1000ms). // Set the timeout for receiving data (1000ms).
status = dc_iostream_set_timeout (device->iostream, 1000); status = dc_iostream_set_timeout (device->iostream, 1000);
if (status != DC_STATUS_SUCCESS) { if (status != DC_STATUS_SUCCESS) {
ERROR (context, "Failed to set the timeout."); ERROR (context, "Failed to set the timeout.");
goto error_close; goto error_free;
} }
// Make sure everything is in a sane state. // Make sure everything is in a sane state.
@ -105,31 +96,12 @@ citizen_aqualand_device_open (dc_device_t **out, dc_context_t *context, const ch
return DC_STATUS_SUCCESS; return DC_STATUS_SUCCESS;
error_close:
dc_iostream_close (device->iostream);
error_free: error_free:
dc_device_deallocate ((dc_device_t *) device); dc_device_deallocate ((dc_device_t *) device);
return status; return status;
} }
static dc_status_t
citizen_aqualand_device_close (dc_device_t *abstract)
{
dc_status_t status = DC_STATUS_SUCCESS;
citizen_aqualand_device_t *device = (citizen_aqualand_device_t*) abstract;
dc_status_t rc = DC_STATUS_SUCCESS;
// Close the device.
rc = dc_iostream_close (device->iostream);
if (rc != DC_STATUS_SUCCESS) {
dc_status_set_error(&status, rc);
}
return status;
}
static dc_status_t static dc_status_t
citizen_aqualand_device_set_fingerprint (dc_device_t *abstract, const unsigned char data[], unsigned int size) citizen_aqualand_device_set_fingerprint (dc_device_t *abstract, const unsigned char data[], unsigned int size)
{ {

View File

@ -23,6 +23,7 @@
#define CITIZEN_AQUALAND_H #define CITIZEN_AQUALAND_H
#include <libdivecomputer/context.h> #include <libdivecomputer/context.h>
#include <libdivecomputer/iostream.h>
#include <libdivecomputer/device.h> #include <libdivecomputer/device.h>
#include <libdivecomputer/parser.h> #include <libdivecomputer/parser.h>
@ -31,7 +32,7 @@ extern "C" {
#endif /* __cplusplus */ #endif /* __cplusplus */
dc_status_t dc_status_t
citizen_aqualand_device_open (dc_device_t **device, dc_context_t *context, const char *name); citizen_aqualand_device_open (dc_device_t **device, dc_context_t *context, dc_iostream_t *iostream);
dc_status_t dc_status_t
citizen_aqualand_parser_create (dc_parser_t **parser, dc_context_t *context); citizen_aqualand_parser_create (dc_parser_t **parser, dc_context_t *context);

View File

@ -26,7 +26,6 @@
#include "cochran_commander.h" #include "cochran_commander.h"
#include "context-private.h" #include "context-private.h"
#include "device-private.h" #include "device-private.h"
#include "serial.h"
#include "array.h" #include "array.h"
#include "ringbuffer.h" #include "ringbuffer.h"
#include "rbstream.h" #include "rbstream.h"
@ -104,7 +103,6 @@ static dc_status_t cochran_commander_device_set_fingerprint (dc_device_t *device
static dc_status_t cochran_commander_device_read (dc_device_t *device, unsigned int address, unsigned char data[], unsigned int size); static dc_status_t cochran_commander_device_read (dc_device_t *device, unsigned int address, unsigned char data[], unsigned int size);
static dc_status_t cochran_commander_device_dump (dc_device_t *device, dc_buffer_t *data); static dc_status_t cochran_commander_device_dump (dc_device_t *device, dc_buffer_t *data);
static dc_status_t cochran_commander_device_foreach (dc_device_t *device, dc_dive_callback_t callback, void *userdata); static dc_status_t cochran_commander_device_foreach (dc_device_t *device, dc_dive_callback_t callback, void *userdata);
static dc_status_t cochran_commander_device_close (dc_device_t *device);
static const dc_device_vtable_t cochran_commander_device_vtable = { static const dc_device_vtable_t cochran_commander_device_vtable = {
sizeof (cochran_commander_device_t), sizeof (cochran_commander_device_t),
@ -115,7 +113,7 @@ static const dc_device_vtable_t cochran_commander_device_vtable = {
cochran_commander_device_dump, /* dump */ cochran_commander_device_dump, /* dump */
cochran_commander_device_foreach, /* foreach */ cochran_commander_device_foreach, /* foreach */
NULL, /* timesync */ NULL, /* timesync */
cochran_commander_device_close /* close */ NULL /* close */
}; };
// Cochran Commander TM, pre-dates pre-21000 s/n // Cochran Commander TM, pre-dates pre-21000 s/n
@ -716,7 +714,7 @@ cochran_commander_find_fingerprint(cochran_commander_device_t *device, cochran_d
dc_status_t dc_status_t
cochran_commander_device_open (dc_device_t **out, dc_context_t *context, const char *name) cochran_commander_device_open (dc_device_t **out, dc_context_t *context, dc_iostream_t *iostream)
{ {
dc_status_t status = DC_STATUS_SUCCESS; dc_status_t status = DC_STATUS_SUCCESS;
cochran_commander_device_t *device = NULL; cochran_commander_device_t *device = NULL;
@ -732,26 +730,19 @@ cochran_commander_device_open (dc_device_t **out, dc_context_t *context, const c
} }
// Set the default values. // Set the default values.
device->iostream = NULL; device->iostream = iostream;
cochran_commander_device_set_fingerprint((dc_device_t *) device, NULL, 0); cochran_commander_device_set_fingerprint((dc_device_t *) device, NULL, 0);
// Open the device.
status = dc_serial_open (&device->iostream, device->base.context, name);
if (status != DC_STATUS_SUCCESS) {
ERROR (device->base.context, "Failed to open the serial port.");
goto error_free;
}
status = cochran_commander_serial_setup(device); status = cochran_commander_serial_setup(device);
if (status != DC_STATUS_SUCCESS) { if (status != DC_STATUS_SUCCESS) {
goto error_close; goto error_free;
} }
// Read ID from the device // Read ID from the device
status = cochran_commander_read_id (device, device->id, sizeof(device->id)); status = cochran_commander_read_id (device, device->id, sizeof(device->id));
if (status != DC_STATUS_SUCCESS) { if (status != DC_STATUS_SUCCESS) {
ERROR (context, "Device not responding."); ERROR (context, "Device not responding.");
goto error_close; goto error_free;
} }
unsigned int model = cochran_commander_get_model(device); unsigned int model = cochran_commander_get_model(device);
@ -777,36 +768,18 @@ cochran_commander_device_open (dc_device_t **out, dc_context_t *context, const c
default: default:
ERROR (context, "Unknown model"); ERROR (context, "Unknown model");
status = DC_STATUS_UNSUPPORTED; status = DC_STATUS_UNSUPPORTED;
goto error_close; goto error_free;
} }
*out = (dc_device_t *) device; *out = (dc_device_t *) device;
return DC_STATUS_SUCCESS; return DC_STATUS_SUCCESS;
error_close:
dc_iostream_close (device->iostream);
error_free: error_free:
dc_device_deallocate ((dc_device_t *) device); dc_device_deallocate ((dc_device_t *) device);
return status; return status;
} }
static dc_status_t
cochran_commander_device_close (dc_device_t *abstract)
{
dc_status_t status = DC_STATUS_SUCCESS;
cochran_commander_device_t *device = (cochran_commander_device_t *) abstract;
dc_status_t rc = DC_STATUS_SUCCESS;
// Close the device.
rc = dc_iostream_close (device->iostream);
if (rc != DC_STATUS_SUCCESS) {
dc_status_set_error(&status, rc);
}
return status;
}
static dc_status_t static dc_status_t
cochran_commander_device_set_fingerprint (dc_device_t *abstract, const unsigned char data[], unsigned int size) cochran_commander_device_set_fingerprint (dc_device_t *abstract, const unsigned char data[], unsigned int size)
{ {

View File

@ -23,6 +23,7 @@
#define COCHRAN_COMMANDER_H #define COCHRAN_COMMANDER_H
#include <libdivecomputer/context.h> #include <libdivecomputer/context.h>
#include <libdivecomputer/iostream.h>
#include <libdivecomputer/device.h> #include <libdivecomputer/device.h>
#include <libdivecomputer/parser.h> #include <libdivecomputer/parser.h>
@ -31,7 +32,7 @@ extern "C" {
#endif /* __cplusplus */ #endif /* __cplusplus */
dc_status_t dc_status_t
cochran_commander_device_open (dc_device_t **device, dc_context_t *context, const char *name); cochran_commander_device_open (dc_device_t **device, dc_context_t *context, dc_iostream_t *iostream);
dc_status_t dc_status_t
cochran_commander_parser_create (dc_parser_t **parser, dc_context_t *context, unsigned int model); cochran_commander_parser_create (dc_parser_t **parser, dc_context_t *context, unsigned int model);

View File

@ -19,6 +19,10 @@
* MA 02110-1301 USA * MA 02110-1301 USA
*/ */
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <stdarg.h> #include <stdarg.h>
@ -313,3 +317,35 @@ dc_context_hexdump (dc_context_t *context, dc_loglevel_t loglevel, const char *f
return DC_STATUS_SUCCESS; return DC_STATUS_SUCCESS;
} }
unsigned int
dc_context_get_transports (dc_context_t *context)
{
UNUSED(context);
return DC_TRANSPORT_SERIAL
#if defined(HAVE_LIBUSB)
| DC_TRANSPORT_USB
#endif
#if defined(HAVE_HIDAPI)
| DC_TRANSPORT_USBHID
#elif defined(HAVE_LIBUSB) && !defined(__APPLE__)
| DC_TRANSPORT_USBHID
#endif
#ifdef _WIN32
#ifdef HAVE_AF_IRDA_H
| DC_TRANSPORT_IRDA
#endif
#ifdef HAVE_WS2BTH_H
| DC_TRANSPORT_BLUETOOTH
#endif
#else /* _WIN32 */
#ifdef HAVE_LINUX_IRDA_H
| DC_TRANSPORT_IRDA
#endif
#ifdef HAVE_BLUEZ
| DC_TRANSPORT_BLUETOOTH
#endif
#endif /* _WIN32 */
;
}

View File

@ -26,7 +26,6 @@
#include "cressi_edy.h" #include "cressi_edy.h"
#include "context-private.h" #include "context-private.h"
#include "device-private.h" #include "device-private.h"
#include "serial.h"
#include "checksum.h" #include "checksum.h"
#include "array.h" #include "array.h"
#include "ringbuffer.h" #include "ringbuffer.h"
@ -218,7 +217,7 @@ cressi_edy_quit (cressi_edy_device_t *device)
dc_status_t dc_status_t
cressi_edy_device_open (dc_device_t **out, dc_context_t *context, const char *name) cressi_edy_device_open (dc_device_t **out, dc_context_t *context, dc_iostream_t *iostream)
{ {
dc_status_t status = DC_STATUS_SUCCESS; dc_status_t status = DC_STATUS_SUCCESS;
cressi_edy_device_t *device = NULL; cressi_edy_device_t *device = NULL;
@ -234,44 +233,37 @@ cressi_edy_device_open (dc_device_t **out, dc_context_t *context, const char *na
} }
// Set the default values. // Set the default values.
device->iostream = NULL; device->iostream = iostream;
device->layout = NULL; device->layout = NULL;
device->model = 0; device->model = 0;
memset (device->fingerprint, 0, sizeof (device->fingerprint)); memset (device->fingerprint, 0, sizeof (device->fingerprint));
// Open the device.
status = dc_serial_open (&device->iostream, context, name);
if (status != DC_STATUS_SUCCESS) {
ERROR (context, "Failed to open the serial port.");
goto error_free;
}
// Set the serial communication protocol (1200 8N1). // Set the serial communication protocol (1200 8N1).
status = dc_iostream_configure (device->iostream, 1200, 8, DC_PARITY_NONE, DC_STOPBITS_ONE, DC_FLOWCONTROL_NONE); status = dc_iostream_configure (device->iostream, 1200, 8, DC_PARITY_NONE, DC_STOPBITS_ONE, DC_FLOWCONTROL_NONE);
if (status != DC_STATUS_SUCCESS) { if (status != DC_STATUS_SUCCESS) {
ERROR (context, "Failed to set the terminal attributes."); ERROR (context, "Failed to set the terminal attributes.");
goto error_close; goto error_free;
} }
// Set the timeout for receiving data (1000 ms). // Set the timeout for receiving data (1000 ms).
status = dc_iostream_set_timeout (device->iostream, 1000); status = dc_iostream_set_timeout (device->iostream, 1000);
if (status != DC_STATUS_SUCCESS) { if (status != DC_STATUS_SUCCESS) {
ERROR (context, "Failed to set the timeout."); ERROR (context, "Failed to set the timeout.");
goto error_close; goto error_free;
} }
// Set the DTR line. // Set the DTR line.
status = dc_iostream_set_dtr (device->iostream, 1); status = dc_iostream_set_dtr (device->iostream, 1);
if (status != DC_STATUS_SUCCESS) { if (status != DC_STATUS_SUCCESS) {
ERROR (context, "Failed to set the DTR line."); ERROR (context, "Failed to set the DTR line.");
goto error_close; goto error_free;
} }
// Clear the RTS line. // Clear the RTS line.
status = dc_iostream_set_rts (device->iostream, 0); status = dc_iostream_set_rts (device->iostream, 0);
if (status != DC_STATUS_SUCCESS) { if (status != DC_STATUS_SUCCESS) {
ERROR (context, "Failed to clear the RTS line."); ERROR (context, "Failed to clear the RTS line.");
goto error_close; goto error_free;
} }
// Make sure everything is in a sane state. // Make sure everything is in a sane state.
@ -293,7 +285,7 @@ cressi_edy_device_open (dc_device_t **out, dc_context_t *context, const char *na
status = dc_iostream_configure (device->iostream, 4800, 8, DC_PARITY_NONE, DC_STOPBITS_ONE, DC_FLOWCONTROL_NONE); status = dc_iostream_configure (device->iostream, 4800, 8, DC_PARITY_NONE, DC_STOPBITS_ONE, DC_FLOWCONTROL_NONE);
if (status != DC_STATUS_SUCCESS) { if (status != DC_STATUS_SUCCESS) {
ERROR (context, "Failed to set the terminal attributes."); ERROR (context, "Failed to set the terminal attributes.");
goto error_close; goto error_free;
} }
// Make sure everything is in a sane state. // Make sure everything is in a sane state.
@ -304,8 +296,6 @@ cressi_edy_device_open (dc_device_t **out, dc_context_t *context, const char *na
return DC_STATUS_SUCCESS; return DC_STATUS_SUCCESS;
error_close:
dc_iostream_close (device->iostream);
error_free: error_free:
dc_device_deallocate ((dc_device_t *) device); dc_device_deallocate ((dc_device_t *) device);
return status; return status;
@ -325,12 +315,6 @@ cressi_edy_device_close (dc_device_t *abstract)
dc_status_set_error(&status, rc); dc_status_set_error(&status, rc);
} }
// Close the device.
rc = dc_iostream_close (device->iostream);
if (rc != DC_STATUS_SUCCESS) {
dc_status_set_error(&status, rc);
}
return status; return status;
} }

View File

@ -23,6 +23,7 @@
#define CRESSI_EDY_H #define CRESSI_EDY_H
#include <libdivecomputer/context.h> #include <libdivecomputer/context.h>
#include <libdivecomputer/iostream.h>
#include <libdivecomputer/device.h> #include <libdivecomputer/device.h>
#include <libdivecomputer/parser.h> #include <libdivecomputer/parser.h>
@ -31,7 +32,7 @@ extern "C" {
#endif /* __cplusplus */ #endif /* __cplusplus */
dc_status_t dc_status_t
cressi_edy_device_open (dc_device_t **device, dc_context_t *context, const char *name); cressi_edy_device_open (dc_device_t **device, dc_context_t *context, dc_iostream_t *iostream);
dc_status_t dc_status_t
cressi_edy_parser_create (dc_parser_t **parser, dc_context_t *context, unsigned int model); cressi_edy_parser_create (dc_parser_t **parser, dc_context_t *context, unsigned int model);

View File

@ -26,7 +26,6 @@
#include "cressi_leonardo.h" #include "cressi_leonardo.h"
#include "context-private.h" #include "context-private.h"
#include "device-private.h" #include "device-private.h"
#include "serial.h"
#include "checksum.h" #include "checksum.h"
#include "array.h" #include "array.h"
#include "ringbuffer.h" #include "ringbuffer.h"
@ -57,7 +56,6 @@ static dc_status_t cressi_leonardo_device_set_fingerprint (dc_device_t *abstract
static dc_status_t cressi_leonardo_device_read (dc_device_t *abstract, unsigned int address, unsigned char data[], unsigned int size); static dc_status_t cressi_leonardo_device_read (dc_device_t *abstract, unsigned int address, unsigned char data[], unsigned int size);
static dc_status_t cressi_leonardo_device_dump (dc_device_t *abstract, dc_buffer_t *buffer); static dc_status_t cressi_leonardo_device_dump (dc_device_t *abstract, dc_buffer_t *buffer);
static dc_status_t cressi_leonardo_device_foreach (dc_device_t *abstract, dc_dive_callback_t callback, void *userdata); static dc_status_t cressi_leonardo_device_foreach (dc_device_t *abstract, dc_dive_callback_t callback, void *userdata);
static dc_status_t cressi_leonardo_device_close (dc_device_t *abstract);
static const dc_device_vtable_t cressi_leonardo_device_vtable = { static const dc_device_vtable_t cressi_leonardo_device_vtable = {
sizeof(cressi_leonardo_device_t), sizeof(cressi_leonardo_device_t),
@ -68,7 +66,7 @@ static const dc_device_vtable_t cressi_leonardo_device_vtable = {
cressi_leonardo_device_dump, /* dump */ cressi_leonardo_device_dump, /* dump */
cressi_leonardo_device_foreach, /* foreach */ cressi_leonardo_device_foreach, /* foreach */
NULL, /* timesync */ NULL, /* timesync */
cressi_leonardo_device_close /* close */ NULL /* close */
}; };
static dc_status_t static dc_status_t
@ -164,7 +162,7 @@ cressi_leonardo_transfer (cressi_leonardo_device_t *device, const unsigned char
} }
dc_status_t dc_status_t
cressi_leonardo_device_open (dc_device_t **out, dc_context_t *context, const char *name) cressi_leonardo_device_open (dc_device_t **out, dc_context_t *context, dc_iostream_t *iostream)
{ {
dc_status_t status = DC_STATUS_SUCCESS; dc_status_t status = DC_STATUS_SUCCESS;
cressi_leonardo_device_t *device = NULL; cressi_leonardo_device_t *device = NULL;
@ -180,42 +178,35 @@ cressi_leonardo_device_open (dc_device_t **out, dc_context_t *context, const cha
} }
// Set the default values. // Set the default values.
device->iostream = NULL; device->iostream = iostream;
memset (device->fingerprint, 0, sizeof (device->fingerprint)); memset (device->fingerprint, 0, sizeof (device->fingerprint));
// Open the device.
status = dc_serial_open (&device->iostream, context, name);
if (status != DC_STATUS_SUCCESS) {
ERROR (context, "Failed to open the serial port.");
goto error_free;
}
// Set the serial communication protocol (115200 8N1). // Set the serial communication protocol (115200 8N1).
status = dc_iostream_configure (device->iostream, 115200, 8, DC_PARITY_NONE, DC_STOPBITS_ONE, DC_FLOWCONTROL_NONE); status = dc_iostream_configure (device->iostream, 115200, 8, DC_PARITY_NONE, DC_STOPBITS_ONE, DC_FLOWCONTROL_NONE);
if (status != DC_STATUS_SUCCESS) { if (status != DC_STATUS_SUCCESS) {
ERROR (context, "Failed to set the terminal attributes."); ERROR (context, "Failed to set the terminal attributes.");
goto error_close; goto error_free;
} }
// Set the timeout for receiving data (1000 ms). // Set the timeout for receiving data (1000 ms).
status = dc_iostream_set_timeout (device->iostream, 1000); status = dc_iostream_set_timeout (device->iostream, 1000);
if (status != DC_STATUS_SUCCESS) { if (status != DC_STATUS_SUCCESS) {
ERROR (context, "Failed to set the timeout."); ERROR (context, "Failed to set the timeout.");
goto error_close; goto error_free;
} }
// Set the RTS line. // Set the RTS line.
status = dc_iostream_set_rts (device->iostream, 1); status = dc_iostream_set_rts (device->iostream, 1);
if (status != DC_STATUS_SUCCESS) { if (status != DC_STATUS_SUCCESS) {
ERROR (context, "Failed to set the RTS line."); ERROR (context, "Failed to set the RTS line.");
goto error_close; goto error_free;
} }
// Set the DTR line. // Set the DTR line.
status = dc_iostream_set_dtr (device->iostream, 1); status = dc_iostream_set_dtr (device->iostream, 1);
if (status != DC_STATUS_SUCCESS) { if (status != DC_STATUS_SUCCESS) {
ERROR (context, "Failed to set the DTR line."); ERROR (context, "Failed to set the DTR line.");
goto error_close; goto error_free;
} }
dc_iostream_sleep (device->iostream, 200); dc_iostream_sleep (device->iostream, 200);
@ -224,7 +215,7 @@ cressi_leonardo_device_open (dc_device_t **out, dc_context_t *context, const cha
status = dc_iostream_set_dtr (device->iostream, 0); status = dc_iostream_set_dtr (device->iostream, 0);
if (status != DC_STATUS_SUCCESS) { if (status != DC_STATUS_SUCCESS) {
ERROR (context, "Failed to clear the DTR line."); ERROR (context, "Failed to clear the DTR line.");
goto error_close; goto error_free;
} }
dc_iostream_sleep (device->iostream, 100); dc_iostream_sleep (device->iostream, 100);
@ -234,29 +225,11 @@ cressi_leonardo_device_open (dc_device_t **out, dc_context_t *context, const cha
return DC_STATUS_SUCCESS; return DC_STATUS_SUCCESS;
error_close:
dc_iostream_close (device->iostream);
error_free: error_free:
dc_device_deallocate ((dc_device_t *) device); dc_device_deallocate ((dc_device_t *) device);
return status; return status;
} }
static dc_status_t
cressi_leonardo_device_close (dc_device_t *abstract)
{
dc_status_t status = DC_STATUS_SUCCESS;
cressi_leonardo_device_t *device = (cressi_leonardo_device_t *) abstract;
dc_status_t rc = DC_STATUS_SUCCESS;
// Close the device.
rc = dc_iostream_close (device->iostream);
if (rc != DC_STATUS_SUCCESS) {
dc_status_set_error(&status, rc);
}
return status;
}
static dc_status_t static dc_status_t
cressi_leonardo_device_set_fingerprint (dc_device_t *abstract, const unsigned char data[], unsigned int size) cressi_leonardo_device_set_fingerprint (dc_device_t *abstract, const unsigned char data[], unsigned int size)
{ {

View File

@ -23,6 +23,7 @@
#define CRESSI_LEONARDO_H #define CRESSI_LEONARDO_H
#include <libdivecomputer/context.h> #include <libdivecomputer/context.h>
#include <libdivecomputer/iostream.h>
#include <libdivecomputer/device.h> #include <libdivecomputer/device.h>
#include <libdivecomputer/parser.h> #include <libdivecomputer/parser.h>
@ -31,7 +32,7 @@ extern "C" {
#endif /* __cplusplus */ #endif /* __cplusplus */
dc_status_t dc_status_t
cressi_leonardo_device_open (dc_device_t **device, dc_context_t *context, const char *name); cressi_leonardo_device_open (dc_device_t **device, dc_context_t *context, dc_iostream_t *iostream);
dc_status_t dc_status_t
cressi_leonardo_parser_create (dc_parser_t **parser, dc_context_t *context, unsigned int model); cressi_leonardo_parser_create (dc_parser_t **parser, dc_context_t *context, unsigned int model);

View File

@ -21,7 +21,7 @@
#include <stdlib.h> // malloc, free #include <stdlib.h> // malloc, free
#include "custom.h" #include <libdivecomputer/custom.h>
#include "iostream-private.h" #include "iostream-private.h"
#include "common-private.h" #include "common-private.h"
@ -69,17 +69,17 @@ static const dc_iostream_vtable_t dc_custom_vtable = {
}; };
dc_status_t dc_status_t
dc_custom_open (dc_iostream_t **out, dc_context_t *context, const dc_custom_cbs_t *callbacks, void *userdata) dc_custom_open (dc_iostream_t **out, dc_context_t *context, dc_transport_t transport, const dc_custom_cbs_t *callbacks, void *userdata)
{ {
dc_custom_t *custom = NULL; dc_custom_t *custom = NULL;
if (out == NULL || callbacks == NULL) if (out == NULL || callbacks == NULL)
return DC_STATUS_INVALIDARGS; return DC_STATUS_INVALIDARGS;
INFO (context, "Open: custom"); INFO (context, "Open: transport=%u", transport);
// Allocate memory. // Allocate memory.
custom = (dc_custom_t *) dc_iostream_allocate (context, &dc_custom_vtable); custom = (dc_custom_t *) dc_iostream_allocate (context, &dc_custom_vtable, transport);
if (custom == NULL) { if (custom == NULL) {
ERROR (context, "Failed to allocate memory."); ERROR (context, "Failed to allocate memory.");
return DC_STATUS_NOMEMORY; return DC_STATUS_NOMEMORY;

View File

@ -19,26 +19,6 @@
* MA 02110-1301 USA * MA 02110-1301 USA
*/ */
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#if defined(HAVE_HIDAPI)
#define USBHID
#elif defined(HAVE_LIBUSB) && !defined(__APPLE__)
#define USBHID
#endif
#ifdef _WIN32
#ifdef HAVE_AF_IRDA_H
#define IRDA
#endif
#else
#ifdef HAVE_LINUX_IRDA_H
#define IRDA
#endif
#endif
#include <stddef.h> #include <stddef.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
@ -61,6 +41,7 @@ struct dc_descriptor_t {
const char *product; const char *product;
dc_family_t type; dc_family_t type;
unsigned int model; unsigned int model;
unsigned int transports;
dc_filter_t filter; dc_filter_t filter;
}; };
@ -84,272 +65,264 @@ static const dc_iterator_vtable_t dc_descriptor_iterator_vtable = {
static const dc_descriptor_t g_descriptors[] = { static const dc_descriptor_t g_descriptors[] = {
/* Suunto Solution */ /* Suunto Solution */
{"Suunto", "Solution", DC_FAMILY_SUUNTO_SOLUTION, 0, NULL}, {"Suunto", "Solution", DC_FAMILY_SUUNTO_SOLUTION, 0, DC_TRANSPORT_SERIAL, NULL},
/* Suunto Eon */ /* Suunto Eon */
{"Suunto", "Eon", DC_FAMILY_SUUNTO_EON, 0, NULL}, {"Suunto", "Eon", DC_FAMILY_SUUNTO_EON, 0, DC_TRANSPORT_SERIAL, NULL},
{"Suunto", "Solution Alpha", DC_FAMILY_SUUNTO_EON, 0, NULL}, {"Suunto", "Solution Alpha", DC_FAMILY_SUUNTO_EON, 0, DC_TRANSPORT_SERIAL, NULL},
{"Suunto", "Solution Nitrox", DC_FAMILY_SUUNTO_EON, 0, NULL}, {"Suunto", "Solution Nitrox", DC_FAMILY_SUUNTO_EON, 0, DC_TRANSPORT_SERIAL, NULL},
/* Suunto Vyper */ /* Suunto Vyper */
{"Suunto", "Spyder", DC_FAMILY_SUUNTO_VYPER, 0x01, NULL}, {"Suunto", "Spyder", DC_FAMILY_SUUNTO_VYPER, 0x01, DC_TRANSPORT_SERIAL, NULL},
{"Suunto", "Stinger", DC_FAMILY_SUUNTO_VYPER, 0x03, NULL}, {"Suunto", "Stinger", DC_FAMILY_SUUNTO_VYPER, 0x03, DC_TRANSPORT_SERIAL, NULL},
{"Suunto", "Mosquito", DC_FAMILY_SUUNTO_VYPER, 0x04, NULL}, {"Suunto", "Mosquito", DC_FAMILY_SUUNTO_VYPER, 0x04, DC_TRANSPORT_SERIAL, NULL},
{"Suunto", "D3", DC_FAMILY_SUUNTO_VYPER, 0x05, NULL}, {"Suunto", "D3", DC_FAMILY_SUUNTO_VYPER, 0x05, DC_TRANSPORT_SERIAL, NULL},
{"Suunto", "Vyper", DC_FAMILY_SUUNTO_VYPER, 0x0A, NULL}, {"Suunto", "Vyper", DC_FAMILY_SUUNTO_VYPER, 0x0A, DC_TRANSPORT_SERIAL, NULL},
{"Suunto", "Vytec", DC_FAMILY_SUUNTO_VYPER, 0X0B, NULL}, {"Suunto", "Vytec", DC_FAMILY_SUUNTO_VYPER, 0X0B, DC_TRANSPORT_SERIAL, NULL},
{"Suunto", "Cobra", DC_FAMILY_SUUNTO_VYPER, 0X0C, NULL}, {"Suunto", "Cobra", DC_FAMILY_SUUNTO_VYPER, 0X0C, DC_TRANSPORT_SERIAL, NULL},
{"Suunto", "Gekko", DC_FAMILY_SUUNTO_VYPER, 0X0D, NULL}, {"Suunto", "Gekko", DC_FAMILY_SUUNTO_VYPER, 0X0D, DC_TRANSPORT_SERIAL, NULL},
{"Suunto", "Zoop", DC_FAMILY_SUUNTO_VYPER, 0x16, NULL}, {"Suunto", "Zoop", DC_FAMILY_SUUNTO_VYPER, 0x16, DC_TRANSPORT_SERIAL, NULL},
/* Suunto Vyper 2 */ /* Suunto Vyper 2 */
{"Suunto", "Vyper 2", DC_FAMILY_SUUNTO_VYPER2, 0x10, NULL}, {"Suunto", "Vyper 2", DC_FAMILY_SUUNTO_VYPER2, 0x10, DC_TRANSPORT_SERIAL, NULL},
{"Suunto", "Cobra 2", DC_FAMILY_SUUNTO_VYPER2, 0x11, NULL}, {"Suunto", "Cobra 2", DC_FAMILY_SUUNTO_VYPER2, 0x11, DC_TRANSPORT_SERIAL, NULL},
{"Suunto", "Vyper Air", DC_FAMILY_SUUNTO_VYPER2, 0x13, NULL}, {"Suunto", "Vyper Air", DC_FAMILY_SUUNTO_VYPER2, 0x13, DC_TRANSPORT_SERIAL, NULL},
{"Suunto", "Cobra 3", DC_FAMILY_SUUNTO_VYPER2, 0x14, NULL}, {"Suunto", "Cobra 3", DC_FAMILY_SUUNTO_VYPER2, 0x14, DC_TRANSPORT_SERIAL, NULL},
{"Suunto", "HelO2", DC_FAMILY_SUUNTO_VYPER2, 0x15, NULL}, {"Suunto", "HelO2", DC_FAMILY_SUUNTO_VYPER2, 0x15, DC_TRANSPORT_SERIAL, NULL},
/* Suunto D9 */ /* Suunto D9 */
{"Suunto", "D9", DC_FAMILY_SUUNTO_D9, 0x0E, NULL}, {"Suunto", "D9", DC_FAMILY_SUUNTO_D9, 0x0E, DC_TRANSPORT_SERIAL, NULL},
{"Suunto", "D6", DC_FAMILY_SUUNTO_D9, 0x0F, NULL}, {"Suunto", "D6", DC_FAMILY_SUUNTO_D9, 0x0F, DC_TRANSPORT_SERIAL, NULL},
{"Suunto", "D4", DC_FAMILY_SUUNTO_D9, 0x12, NULL}, {"Suunto", "D4", DC_FAMILY_SUUNTO_D9, 0x12, DC_TRANSPORT_SERIAL, NULL},
{"Suunto", "D4i", DC_FAMILY_SUUNTO_D9, 0x19, NULL}, {"Suunto", "D4i", DC_FAMILY_SUUNTO_D9, 0x19, DC_TRANSPORT_SERIAL, NULL},
{"Suunto", "D6i", DC_FAMILY_SUUNTO_D9, 0x1A, NULL}, {"Suunto", "D6i", DC_FAMILY_SUUNTO_D9, 0x1A, DC_TRANSPORT_SERIAL, NULL},
{"Suunto", "D9tx", DC_FAMILY_SUUNTO_D9, 0x1B, NULL}, {"Suunto", "D9tx", DC_FAMILY_SUUNTO_D9, 0x1B, DC_TRANSPORT_SERIAL, NULL},
{"Suunto", "DX", DC_FAMILY_SUUNTO_D9, 0x1C, NULL}, {"Suunto", "DX", DC_FAMILY_SUUNTO_D9, 0x1C, DC_TRANSPORT_SERIAL, NULL},
{"Suunto", "Vyper Novo", DC_FAMILY_SUUNTO_D9, 0x1D, NULL}, {"Suunto", "Vyper Novo", DC_FAMILY_SUUNTO_D9, 0x1D, DC_TRANSPORT_SERIAL, NULL},
{"Suunto", "Zoop Novo", DC_FAMILY_SUUNTO_D9, 0x1E, NULL}, {"Suunto", "Zoop Novo", DC_FAMILY_SUUNTO_D9, 0x1E, DC_TRANSPORT_SERIAL, NULL},
{"Suunto", "D4f", DC_FAMILY_SUUNTO_D9, 0x20, NULL}, {"Suunto", "D4f", DC_FAMILY_SUUNTO_D9, 0x20, DC_TRANSPORT_SERIAL, NULL},
/* Suunto EON Steel */ /* Suunto EON Steel */
#ifdef USBHID {"Suunto", "EON Steel", DC_FAMILY_SUUNTO_EONSTEEL, 0, DC_TRANSPORT_USBHID, dc_filter_suunto},
{"Suunto", "EON Steel", DC_FAMILY_SUUNTO_EONSTEEL, 0, dc_filter_suunto}, {"Suunto", "EON Core", DC_FAMILY_SUUNTO_EONSTEEL, 1, DC_TRANSPORT_USBHID, dc_filter_suunto},
{"Suunto", "EON Core", DC_FAMILY_SUUNTO_EONSTEEL, 1, dc_filter_suunto},
#endif
/* Uwatec Aladin */ /* Uwatec Aladin */
{"Uwatec", "Aladin Air Twin", DC_FAMILY_UWATEC_ALADIN, 0x1C, NULL}, {"Uwatec", "Aladin Air Twin", DC_FAMILY_UWATEC_ALADIN, 0x1C, DC_TRANSPORT_SERIAL, NULL},
{"Uwatec", "Aladin Sport Plus", DC_FAMILY_UWATEC_ALADIN, 0x3E, NULL}, {"Uwatec", "Aladin Sport Plus", DC_FAMILY_UWATEC_ALADIN, 0x3E, DC_TRANSPORT_SERIAL, NULL},
{"Uwatec", "Aladin Pro", DC_FAMILY_UWATEC_ALADIN, 0x3F, NULL}, {"Uwatec", "Aladin Pro", DC_FAMILY_UWATEC_ALADIN, 0x3F, DC_TRANSPORT_SERIAL, NULL},
{"Uwatec", "Aladin Air Z", DC_FAMILY_UWATEC_ALADIN, 0x44, NULL}, {"Uwatec", "Aladin Air Z", DC_FAMILY_UWATEC_ALADIN, 0x44, DC_TRANSPORT_SERIAL, NULL},
{"Uwatec", "Aladin Air Z O2", DC_FAMILY_UWATEC_ALADIN, 0xA4, NULL}, {"Uwatec", "Aladin Air Z O2", DC_FAMILY_UWATEC_ALADIN, 0xA4, DC_TRANSPORT_SERIAL, NULL},
{"Uwatec", "Aladin Air Z Nitrox", DC_FAMILY_UWATEC_ALADIN, 0xF4, NULL}, {"Uwatec", "Aladin Air Z Nitrox", DC_FAMILY_UWATEC_ALADIN, 0xF4, DC_TRANSPORT_SERIAL, NULL},
{"Uwatec", "Aladin Pro Ultra", DC_FAMILY_UWATEC_ALADIN, 0xFF, NULL}, {"Uwatec", "Aladin Pro Ultra", DC_FAMILY_UWATEC_ALADIN, 0xFF, DC_TRANSPORT_SERIAL, NULL},
/* Uwatec Memomouse */ /* Uwatec Memomouse */
{"Uwatec", "Memomouse", DC_FAMILY_UWATEC_MEMOMOUSE, 0, NULL}, {"Uwatec", "Memomouse", DC_FAMILY_UWATEC_MEMOMOUSE, 0, DC_TRANSPORT_SERIAL, NULL},
/* Uwatec Smart */ /* Uwatec Smart */
#ifdef IRDA {"Uwatec", "Smart Pro", DC_FAMILY_UWATEC_SMART, 0x10, DC_TRANSPORT_IRDA, dc_filter_uwatec},
{"Uwatec", "Smart Pro", DC_FAMILY_UWATEC_SMART, 0x10, dc_filter_uwatec}, {"Uwatec", "Galileo Sol", DC_FAMILY_UWATEC_SMART, 0x11, DC_TRANSPORT_IRDA, dc_filter_uwatec},
{"Uwatec", "Galileo Sol", DC_FAMILY_UWATEC_SMART, 0x11, dc_filter_uwatec}, {"Uwatec", "Galileo Luna", DC_FAMILY_UWATEC_SMART, 0x11, DC_TRANSPORT_IRDA, dc_filter_uwatec},
{"Uwatec", "Galileo Luna", DC_FAMILY_UWATEC_SMART, 0x11, dc_filter_uwatec}, {"Uwatec", "Galileo Terra", DC_FAMILY_UWATEC_SMART, 0x11, DC_TRANSPORT_IRDA, dc_filter_uwatec},
{"Uwatec", "Galileo Terra", DC_FAMILY_UWATEC_SMART, 0x11, dc_filter_uwatec}, {"Uwatec", "Aladin Tec", DC_FAMILY_UWATEC_SMART, 0x12, DC_TRANSPORT_IRDA, dc_filter_uwatec},
{"Uwatec", "Aladin Tec", DC_FAMILY_UWATEC_SMART, 0x12, dc_filter_uwatec}, {"Uwatec", "Aladin Prime", DC_FAMILY_UWATEC_SMART, 0x12, DC_TRANSPORT_IRDA, dc_filter_uwatec},
{"Uwatec", "Aladin Prime", DC_FAMILY_UWATEC_SMART, 0x12, dc_filter_uwatec}, {"Uwatec", "Aladin Tec 2G", DC_FAMILY_UWATEC_SMART, 0x13, DC_TRANSPORT_IRDA, dc_filter_uwatec},
{"Uwatec", "Aladin Tec 2G", DC_FAMILY_UWATEC_SMART, 0x13, dc_filter_uwatec}, {"Uwatec", "Aladin 2G", DC_FAMILY_UWATEC_SMART, 0x13, DC_TRANSPORT_IRDA, dc_filter_uwatec},
{"Uwatec", "Aladin 2G", DC_FAMILY_UWATEC_SMART, 0x13, dc_filter_uwatec}, {"Subgear","XP-10", DC_FAMILY_UWATEC_SMART, 0x13, DC_TRANSPORT_IRDA, dc_filter_uwatec},
{"Subgear","XP-10", DC_FAMILY_UWATEC_SMART, 0x13, dc_filter_uwatec}, {"Uwatec", "Smart Com", DC_FAMILY_UWATEC_SMART, 0x14, DC_TRANSPORT_IRDA, dc_filter_uwatec},
{"Uwatec", "Smart Com", DC_FAMILY_UWATEC_SMART, 0x14, dc_filter_uwatec}, {"Uwatec", "Aladin 2G", DC_FAMILY_UWATEC_SMART, 0x15, DC_TRANSPORT_IRDA, dc_filter_uwatec},
{"Uwatec", "Aladin 2G", DC_FAMILY_UWATEC_SMART, 0x15, dc_filter_uwatec}, {"Uwatec", "Aladin Tec 3G", DC_FAMILY_UWATEC_SMART, 0x15, DC_TRANSPORT_IRDA, dc_filter_uwatec},
{"Uwatec", "Aladin Tec 3G", DC_FAMILY_UWATEC_SMART, 0x15, dc_filter_uwatec}, {"Uwatec", "Aladin Sport", DC_FAMILY_UWATEC_SMART, 0x15, DC_TRANSPORT_IRDA, dc_filter_uwatec},
{"Uwatec", "Aladin Sport", DC_FAMILY_UWATEC_SMART, 0x15, dc_filter_uwatec}, {"Subgear","XP-3G", DC_FAMILY_UWATEC_SMART, 0x15, DC_TRANSPORT_IRDA, dc_filter_uwatec},
{"Subgear","XP-3G", DC_FAMILY_UWATEC_SMART, 0x15, dc_filter_uwatec}, {"Uwatec", "Smart Tec", DC_FAMILY_UWATEC_SMART, 0x18, DC_TRANSPORT_IRDA, dc_filter_uwatec},
{"Uwatec", "Smart Tec", DC_FAMILY_UWATEC_SMART, 0x18, dc_filter_uwatec}, {"Uwatec", "Galileo Trimix",DC_FAMILY_UWATEC_SMART, 0x19, DC_TRANSPORT_IRDA, dc_filter_uwatec},
{"Uwatec", "Galileo Trimix",DC_FAMILY_UWATEC_SMART, 0x19, dc_filter_uwatec}, {"Uwatec", "Smart Z", DC_FAMILY_UWATEC_SMART, 0x1C, DC_TRANSPORT_IRDA, dc_filter_uwatec},
{"Uwatec", "Smart Z", DC_FAMILY_UWATEC_SMART, 0x1C, dc_filter_uwatec}, {"Subgear","XP Air", DC_FAMILY_UWATEC_SMART, 0x1C, DC_TRANSPORT_IRDA, dc_filter_uwatec},
{"Subgear","XP Air", DC_FAMILY_UWATEC_SMART, 0x1C, dc_filter_uwatec},
#endif
/* Scubapro/Uwatec Meridian */ /* Scubapro/Uwatec Meridian */
{"Scubapro", "Meridian", DC_FAMILY_UWATEC_MERIDIAN, 0x20, NULL}, {"Scubapro", "Meridian", DC_FAMILY_UWATEC_MERIDIAN, 0x20, DC_TRANSPORT_SERIAL, NULL},
{"Scubapro", "Mantis", DC_FAMILY_UWATEC_MERIDIAN, 0x20, NULL}, {"Scubapro", "Mantis", DC_FAMILY_UWATEC_MERIDIAN, 0x20, DC_TRANSPORT_SERIAL, NULL},
{"Scubapro", "Chromis", DC_FAMILY_UWATEC_MERIDIAN, 0x24, NULL}, {"Scubapro", "Chromis", DC_FAMILY_UWATEC_MERIDIAN, 0x24, DC_TRANSPORT_SERIAL, NULL},
{"Scubapro", "Mantis 2", DC_FAMILY_UWATEC_MERIDIAN, 0x26, NULL}, {"Scubapro", "Mantis 2", DC_FAMILY_UWATEC_MERIDIAN, 0x26, DC_TRANSPORT_SERIAL, NULL},
/* Scubapro G2 */ /* Scubapro G2 */
#ifdef USBHID {"Scubapro", "Aladin Sport Matrix", DC_FAMILY_UWATEC_G2, 0x17, DC_TRANSPORT_NONE, dc_filter_uwatec},
{"Scubapro", "Aladin Sport Matrix", DC_FAMILY_UWATEC_G2, 0x17, dc_filter_uwatec}, {"Scubapro", "Aladin Square", DC_FAMILY_UWATEC_G2, 0x22, DC_TRANSPORT_USBHID, dc_filter_uwatec},
{"Scubapro", "Aladin Square", DC_FAMILY_UWATEC_G2, 0x22, dc_filter_uwatec}, {"Scubapro", "G2", DC_FAMILY_UWATEC_G2, 0x32, DC_TRANSPORT_USBHID, dc_filter_uwatec},
{"Scubapro", "G2", DC_FAMILY_UWATEC_G2, 0x32, dc_filter_uwatec},
#endif
/* Reefnet */ /* Reefnet */
{"Reefnet", "Sensus", DC_FAMILY_REEFNET_SENSUS, 1, NULL}, {"Reefnet", "Sensus", DC_FAMILY_REEFNET_SENSUS, 1, DC_TRANSPORT_SERIAL, NULL},
{"Reefnet", "Sensus Pro", DC_FAMILY_REEFNET_SENSUSPRO, 2, NULL}, {"Reefnet", "Sensus Pro", DC_FAMILY_REEFNET_SENSUSPRO, 2, DC_TRANSPORT_SERIAL, NULL},
{"Reefnet", "Sensus Ultra", DC_FAMILY_REEFNET_SENSUSULTRA, 3, NULL}, {"Reefnet", "Sensus Ultra", DC_FAMILY_REEFNET_SENSUSULTRA, 3, DC_TRANSPORT_SERIAL, NULL},
/* Oceanic VT Pro */ /* Oceanic VT Pro */
{"Aeris", "500 AI", DC_FAMILY_OCEANIC_VTPRO, 0x4151, NULL}, {"Aeris", "500 AI", DC_FAMILY_OCEANIC_VTPRO, 0x4151, DC_TRANSPORT_SERIAL, NULL},
{"Oceanic", "Versa Pro", DC_FAMILY_OCEANIC_VTPRO, 0x4155, NULL}, {"Oceanic", "Versa Pro", DC_FAMILY_OCEANIC_VTPRO, 0x4155, DC_TRANSPORT_SERIAL, NULL},
{"Aeris", "Atmos 2", DC_FAMILY_OCEANIC_VTPRO, 0x4158, NULL}, {"Aeris", "Atmos 2", DC_FAMILY_OCEANIC_VTPRO, 0x4158, DC_TRANSPORT_SERIAL, NULL},
{"Oceanic", "Pro Plus 2", DC_FAMILY_OCEANIC_VTPRO, 0x4159, NULL}, {"Oceanic", "Pro Plus 2", DC_FAMILY_OCEANIC_VTPRO, 0x4159, DC_TRANSPORT_SERIAL, NULL},
{"Aeris", "Atmos AI", DC_FAMILY_OCEANIC_VTPRO, 0x4244, NULL}, {"Aeris", "Atmos AI", DC_FAMILY_OCEANIC_VTPRO, 0x4244, DC_TRANSPORT_SERIAL, NULL},
{"Oceanic", "VT Pro", DC_FAMILY_OCEANIC_VTPRO, 0x4245, NULL}, {"Oceanic", "VT Pro", DC_FAMILY_OCEANIC_VTPRO, 0x4245, DC_TRANSPORT_SERIAL, NULL},
{"Sherwood", "Wisdom", DC_FAMILY_OCEANIC_VTPRO, 0x4246, NULL}, {"Sherwood", "Wisdom", DC_FAMILY_OCEANIC_VTPRO, 0x4246, DC_TRANSPORT_SERIAL, NULL},
{"Aeris", "Elite", DC_FAMILY_OCEANIC_VTPRO, 0x424F, NULL}, {"Aeris", "Elite", DC_FAMILY_OCEANIC_VTPRO, 0x424F, DC_TRANSPORT_SERIAL, NULL},
/* Oceanic Veo 250 */ /* Oceanic Veo 250 */
{"Genesis", "React Pro", DC_FAMILY_OCEANIC_VEO250, 0x4247, NULL}, {"Genesis", "React Pro", DC_FAMILY_OCEANIC_VEO250, 0x4247, DC_TRANSPORT_SERIAL, NULL},
{"Oceanic", "Veo 200", DC_FAMILY_OCEANIC_VEO250, 0x424B, NULL}, {"Oceanic", "Veo 200", DC_FAMILY_OCEANIC_VEO250, 0x424B, DC_TRANSPORT_SERIAL, NULL},
{"Oceanic", "Veo 250", DC_FAMILY_OCEANIC_VEO250, 0x424C, NULL}, {"Oceanic", "Veo 250", DC_FAMILY_OCEANIC_VEO250, 0x424C, DC_TRANSPORT_SERIAL, NULL},
{"Seemann", "XP5", DC_FAMILY_OCEANIC_VEO250, 0x4251, NULL}, {"Seemann", "XP5", DC_FAMILY_OCEANIC_VEO250, 0x4251, DC_TRANSPORT_SERIAL, NULL},
{"Oceanic", "Veo 180", DC_FAMILY_OCEANIC_VEO250, 0x4252, NULL}, {"Oceanic", "Veo 180", DC_FAMILY_OCEANIC_VEO250, 0x4252, DC_TRANSPORT_SERIAL, NULL},
{"Aeris", "XR-2", DC_FAMILY_OCEANIC_VEO250, 0x4255, NULL}, {"Aeris", "XR-2", DC_FAMILY_OCEANIC_VEO250, 0x4255, DC_TRANSPORT_SERIAL, NULL},
{"Sherwood", "Insight", DC_FAMILY_OCEANIC_VEO250, 0x425A, NULL}, {"Sherwood", "Insight", DC_FAMILY_OCEANIC_VEO250, 0x425A, DC_TRANSPORT_SERIAL, NULL},
{"Hollis", "DG02", DC_FAMILY_OCEANIC_VEO250, 0x4352, NULL}, {"Hollis", "DG02", DC_FAMILY_OCEANIC_VEO250, 0x4352, DC_TRANSPORT_SERIAL, NULL},
/* Oceanic Atom 2.0 */ /* Oceanic Atom 2.0 */
{"Oceanic", "Atom 1.0", DC_FAMILY_OCEANIC_ATOM2, 0x4250, NULL}, {"Oceanic", "Atom 1.0", DC_FAMILY_OCEANIC_ATOM2, 0x4250, DC_TRANSPORT_SERIAL, NULL},
{"Aeris", "Epic", DC_FAMILY_OCEANIC_ATOM2, 0x4257, NULL}, {"Aeris", "Epic", DC_FAMILY_OCEANIC_ATOM2, 0x4257, DC_TRANSPORT_SERIAL, NULL},
{"Oceanic", "VT3", DC_FAMILY_OCEANIC_ATOM2, 0x4258, NULL}, {"Oceanic", "VT3", DC_FAMILY_OCEANIC_ATOM2, 0x4258, DC_TRANSPORT_SERIAL, NULL},
{"Aeris", "Elite T3", DC_FAMILY_OCEANIC_ATOM2, 0x4259, NULL}, {"Aeris", "Elite T3", DC_FAMILY_OCEANIC_ATOM2, 0x4259, DC_TRANSPORT_SERIAL, NULL},
{"Oceanic", "Atom 2.0", DC_FAMILY_OCEANIC_ATOM2, 0x4342, NULL}, {"Oceanic", "Atom 2.0", DC_FAMILY_OCEANIC_ATOM2, 0x4342, DC_TRANSPORT_SERIAL, NULL},
{"Oceanic", "Geo", DC_FAMILY_OCEANIC_ATOM2, 0x4344, NULL}, {"Oceanic", "Geo", DC_FAMILY_OCEANIC_ATOM2, 0x4344, DC_TRANSPORT_SERIAL, NULL},
{"Aeris", "Manta", DC_FAMILY_OCEANIC_ATOM2, 0x4345, NULL}, {"Aeris", "Manta", DC_FAMILY_OCEANIC_ATOM2, 0x4345, DC_TRANSPORT_SERIAL, NULL},
{"Aeris", "XR-1 NX", DC_FAMILY_OCEANIC_ATOM2, 0x4346, NULL}, {"Aeris", "XR-1 NX", DC_FAMILY_OCEANIC_ATOM2, 0x4346, DC_TRANSPORT_SERIAL, NULL},
{"Oceanic", "Datamask", DC_FAMILY_OCEANIC_ATOM2, 0x4347, NULL}, {"Oceanic", "Datamask", DC_FAMILY_OCEANIC_ATOM2, 0x4347, DC_TRANSPORT_SERIAL, NULL},
{"Aeris", "Compumask", DC_FAMILY_OCEANIC_ATOM2, 0x4348, NULL}, {"Aeris", "Compumask", DC_FAMILY_OCEANIC_ATOM2, 0x4348, DC_TRANSPORT_SERIAL, NULL},
{"Aeris", "F10", DC_FAMILY_OCEANIC_ATOM2, 0x434D, NULL}, {"Aeris", "F10", DC_FAMILY_OCEANIC_ATOM2, 0x434D, DC_TRANSPORT_SERIAL, NULL},
{"Oceanic", "OC1", DC_FAMILY_OCEANIC_ATOM2, 0x434E, NULL}, {"Oceanic", "OC1", DC_FAMILY_OCEANIC_ATOM2, 0x434E, DC_TRANSPORT_SERIAL, NULL},
{"Sherwood", "Wisdom 2", DC_FAMILY_OCEANIC_ATOM2, 0x4350, NULL}, {"Sherwood", "Wisdom 2", DC_FAMILY_OCEANIC_ATOM2, 0x4350, DC_TRANSPORT_SERIAL, NULL},
{"Sherwood", "Insight 2", DC_FAMILY_OCEANIC_ATOM2, 0x4353, NULL}, {"Sherwood", "Insight 2", DC_FAMILY_OCEANIC_ATOM2, 0x4353, DC_TRANSPORT_SERIAL, NULL},
{"Genesis", "React Pro White", DC_FAMILY_OCEANIC_ATOM2, 0x4354, NULL}, {"Genesis", "React Pro White", DC_FAMILY_OCEANIC_ATOM2, 0x4354, DC_TRANSPORT_SERIAL, NULL},
{"Tusa", "Element II (IQ-750)", DC_FAMILY_OCEANIC_ATOM2, 0x4357, NULL}, {"Tusa", "Element II (IQ-750)", DC_FAMILY_OCEANIC_ATOM2, 0x4357, DC_TRANSPORT_SERIAL, NULL},
{"Oceanic", "Veo 1.0", DC_FAMILY_OCEANIC_ATOM2, 0x4358, NULL}, {"Oceanic", "Veo 1.0", DC_FAMILY_OCEANIC_ATOM2, 0x4358, DC_TRANSPORT_SERIAL, NULL},
{"Oceanic", "Veo 2.0", DC_FAMILY_OCEANIC_ATOM2, 0x4359, NULL}, {"Oceanic", "Veo 2.0", DC_FAMILY_OCEANIC_ATOM2, 0x4359, DC_TRANSPORT_SERIAL, NULL},
{"Oceanic", "Veo 3.0", DC_FAMILY_OCEANIC_ATOM2, 0x435A, NULL}, {"Oceanic", "Veo 3.0", DC_FAMILY_OCEANIC_ATOM2, 0x435A, DC_TRANSPORT_SERIAL, NULL},
{"Tusa", "Zen (IQ-900)", DC_FAMILY_OCEANIC_ATOM2, 0x4441, NULL}, {"Tusa", "Zen (IQ-900)", DC_FAMILY_OCEANIC_ATOM2, 0x4441, DC_TRANSPORT_SERIAL, NULL},
{"Tusa", "Zen Air (IQ-950)", DC_FAMILY_OCEANIC_ATOM2, 0x4442, NULL}, {"Tusa", "Zen Air (IQ-950)", DC_FAMILY_OCEANIC_ATOM2, 0x4442, DC_TRANSPORT_SERIAL, NULL},
{"Aeris", "Atmos AI 2", DC_FAMILY_OCEANIC_ATOM2, 0x4443, NULL}, {"Aeris", "Atmos AI 2", DC_FAMILY_OCEANIC_ATOM2, 0x4443, DC_TRANSPORT_SERIAL, NULL},
{"Oceanic", "Pro Plus 2.1", DC_FAMILY_OCEANIC_ATOM2, 0x4444, NULL}, {"Oceanic", "Pro Plus 2.1", DC_FAMILY_OCEANIC_ATOM2, 0x4444, DC_TRANSPORT_SERIAL, NULL},
{"Oceanic", "Geo 2.0", DC_FAMILY_OCEANIC_ATOM2, 0x4446, NULL}, {"Oceanic", "Geo 2.0", DC_FAMILY_OCEANIC_ATOM2, 0x4446, DC_TRANSPORT_SERIAL, NULL},
{"Oceanic", "VT4", DC_FAMILY_OCEANIC_ATOM2, 0x4447, NULL}, {"Oceanic", "VT4", DC_FAMILY_OCEANIC_ATOM2, 0x4447, DC_TRANSPORT_SERIAL, NULL},
{"Oceanic", "OC1", DC_FAMILY_OCEANIC_ATOM2, 0x4449, NULL}, {"Oceanic", "OC1", DC_FAMILY_OCEANIC_ATOM2, 0x4449, DC_TRANSPORT_SERIAL, NULL},
{"Beuchat", "Voyager 2G", DC_FAMILY_OCEANIC_ATOM2, 0x444B, NULL}, {"Beuchat", "Voyager 2G", DC_FAMILY_OCEANIC_ATOM2, 0x444B, DC_TRANSPORT_SERIAL, NULL},
{"Oceanic", "Atom 3.0", DC_FAMILY_OCEANIC_ATOM2, 0x444C, NULL}, {"Oceanic", "Atom 3.0", DC_FAMILY_OCEANIC_ATOM2, 0x444C, DC_TRANSPORT_SERIAL, NULL},
{"Hollis", "DG03", DC_FAMILY_OCEANIC_ATOM2, 0x444D, NULL}, {"Hollis", "DG03", DC_FAMILY_OCEANIC_ATOM2, 0x444D, DC_TRANSPORT_SERIAL, NULL},
{"Oceanic", "OCS", DC_FAMILY_OCEANIC_ATOM2, 0x4450, NULL}, {"Oceanic", "OCS", DC_FAMILY_OCEANIC_ATOM2, 0x4450, DC_TRANSPORT_SERIAL, NULL},
{"Oceanic", "OC1", DC_FAMILY_OCEANIC_ATOM2, 0x4451, NULL}, {"Oceanic", "OC1", DC_FAMILY_OCEANIC_ATOM2, 0x4451, DC_TRANSPORT_SERIAL, NULL},
{"Oceanic", "VT 4.1", DC_FAMILY_OCEANIC_ATOM2, 0x4452, NULL}, {"Oceanic", "VT 4.1", DC_FAMILY_OCEANIC_ATOM2, 0x4452, DC_TRANSPORT_SERIAL, NULL},
{"Aeris", "Epic", DC_FAMILY_OCEANIC_ATOM2, 0x4453, NULL}, {"Aeris", "Epic", DC_FAMILY_OCEANIC_ATOM2, 0x4453, DC_TRANSPORT_SERIAL, NULL},
{"Aeris", "Elite T3", DC_FAMILY_OCEANIC_ATOM2, 0x4455, NULL}, {"Aeris", "Elite T3", DC_FAMILY_OCEANIC_ATOM2, 0x4455, DC_TRANSPORT_SERIAL, NULL},
{"Oceanic", "Atom 3.1", DC_FAMILY_OCEANIC_ATOM2, 0x4456, NULL}, {"Oceanic", "Atom 3.1", DC_FAMILY_OCEANIC_ATOM2, 0x4456, DC_TRANSPORT_SERIAL, NULL},
{"Aeris", "A300 AI", DC_FAMILY_OCEANIC_ATOM2, 0x4457, NULL}, {"Aeris", "A300 AI", DC_FAMILY_OCEANIC_ATOM2, 0x4457, DC_TRANSPORT_SERIAL, NULL},
{"Sherwood", "Wisdom 3", DC_FAMILY_OCEANIC_ATOM2, 0x4458, NULL}, {"Sherwood", "Wisdom 3", DC_FAMILY_OCEANIC_ATOM2, 0x4458, DC_TRANSPORT_SERIAL, NULL},
{"Aeris", "A300", DC_FAMILY_OCEANIC_ATOM2, 0x445A, NULL}, {"Aeris", "A300", DC_FAMILY_OCEANIC_ATOM2, 0x445A, DC_TRANSPORT_SERIAL, NULL},
{"Hollis", "TX1", DC_FAMILY_OCEANIC_ATOM2, 0x4542, NULL}, {"Hollis", "TX1", DC_FAMILY_OCEANIC_ATOM2, 0x4542, DC_TRANSPORT_SERIAL, NULL},
{"Beuchat", "Mundial 2", DC_FAMILY_OCEANIC_ATOM2, 0x4543, NULL}, {"Beuchat", "Mundial 2", DC_FAMILY_OCEANIC_ATOM2, 0x4543, DC_TRANSPORT_SERIAL, NULL},
{"Sherwood", "Amphos", DC_FAMILY_OCEANIC_ATOM2, 0x4545, NULL}, {"Sherwood", "Amphos", DC_FAMILY_OCEANIC_ATOM2, 0x4545, DC_TRANSPORT_SERIAL, NULL},
{"Sherwood", "Amphos Air", DC_FAMILY_OCEANIC_ATOM2, 0x4546, NULL}, {"Sherwood", "Amphos Air", DC_FAMILY_OCEANIC_ATOM2, 0x4546, DC_TRANSPORT_SERIAL, NULL},
{"Oceanic", "Pro Plus 3", DC_FAMILY_OCEANIC_ATOM2, 0x4548, NULL}, {"Oceanic", "Pro Plus 3", DC_FAMILY_OCEANIC_ATOM2, 0x4548, DC_TRANSPORT_SERIAL, NULL},
{"Aeris", "F11", DC_FAMILY_OCEANIC_ATOM2, 0x4549, NULL}, {"Aeris", "F11", DC_FAMILY_OCEANIC_ATOM2, 0x4549, DC_TRANSPORT_SERIAL, NULL},
{"Oceanic", "OCi", DC_FAMILY_OCEANIC_ATOM2, 0x454B, NULL}, {"Oceanic", "OCi", DC_FAMILY_OCEANIC_ATOM2, 0x454B, DC_TRANSPORT_SERIAL, NULL},
{"Aeris", "A300CS", DC_FAMILY_OCEANIC_ATOM2, 0x454C, NULL}, {"Aeris", "A300CS", DC_FAMILY_OCEANIC_ATOM2, 0x454C, DC_TRANSPORT_SERIAL, NULL},
{"Beuchat", "Mundial 3", DC_FAMILY_OCEANIC_ATOM2, 0x4550, NULL}, {"Beuchat", "Mundial 3", DC_FAMILY_OCEANIC_ATOM2, 0x4550, DC_TRANSPORT_SERIAL, NULL},
{"Oceanic", "F10", DC_FAMILY_OCEANIC_ATOM2, 0x4553, NULL}, {"Oceanic", "F10", DC_FAMILY_OCEANIC_ATOM2, 0x4553, DC_TRANSPORT_SERIAL, NULL},
{"Oceanic", "F11", DC_FAMILY_OCEANIC_ATOM2, 0x4554, NULL}, {"Oceanic", "F11", DC_FAMILY_OCEANIC_ATOM2, 0x4554, DC_TRANSPORT_SERIAL, NULL},
{"Subgear", "XP-Air", DC_FAMILY_OCEANIC_ATOM2, 0x4555, NULL}, {"Subgear", "XP-Air", DC_FAMILY_OCEANIC_ATOM2, 0x4555, DC_TRANSPORT_SERIAL, NULL},
{"Sherwood", "Vision", DC_FAMILY_OCEANIC_ATOM2, 0x4556, NULL}, {"Sherwood", "Vision", DC_FAMILY_OCEANIC_ATOM2, 0x4556, DC_TRANSPORT_SERIAL, NULL},
{"Oceanic", "VTX", DC_FAMILY_OCEANIC_ATOM2, 0x4557, NULL}, {"Oceanic", "VTX", DC_FAMILY_OCEANIC_ATOM2, 0x4557, DC_TRANSPORT_SERIAL, NULL},
{"Aqualung", "i300", DC_FAMILY_OCEANIC_ATOM2, 0x4559, NULL}, {"Aqualung", "i300", DC_FAMILY_OCEANIC_ATOM2, 0x4559, DC_TRANSPORT_SERIAL, NULL},
{"Aqualung", "i750TC", DC_FAMILY_OCEANIC_ATOM2, 0x455A, NULL}, {"Aqualung", "i750TC", DC_FAMILY_OCEANIC_ATOM2, 0x455A, DC_TRANSPORT_SERIAL, NULL},
{"Aqualung", "i450T", DC_FAMILY_OCEANIC_ATOM2, 0x4641, NULL}, {"Aqualung", "i450T", DC_FAMILY_OCEANIC_ATOM2, 0x4641, DC_TRANSPORT_SERIAL, NULL},
{"Aqualung", "i550", DC_FAMILY_OCEANIC_ATOM2, 0x4642, NULL}, {"Aqualung", "i550", DC_FAMILY_OCEANIC_ATOM2, 0x4642, DC_TRANSPORT_SERIAL, NULL},
{"Aqualung", "i200", DC_FAMILY_OCEANIC_ATOM2, 0x4646, NULL}, {"Aqualung", "i200", DC_FAMILY_OCEANIC_ATOM2, 0x4646, DC_TRANSPORT_SERIAL, NULL},
/* Mares Nemo */ /* Mares Nemo */
{"Mares", "Nemo", DC_FAMILY_MARES_NEMO, 0, NULL}, {"Mares", "Nemo", DC_FAMILY_MARES_NEMO, 0, DC_TRANSPORT_SERIAL, NULL},
{"Mares", "Nemo Steel", DC_FAMILY_MARES_NEMO, 0, NULL}, {"Mares", "Nemo Steel", DC_FAMILY_MARES_NEMO, 0, DC_TRANSPORT_SERIAL, NULL},
{"Mares", "Nemo Titanium",DC_FAMILY_MARES_NEMO, 0, NULL}, {"Mares", "Nemo Titanium",DC_FAMILY_MARES_NEMO, 0, DC_TRANSPORT_SERIAL, NULL},
{"Mares", "Nemo Excel", DC_FAMILY_MARES_NEMO, 17, NULL}, {"Mares", "Nemo Excel", DC_FAMILY_MARES_NEMO, 17, DC_TRANSPORT_SERIAL, NULL},
{"Mares", "Nemo Apneist", DC_FAMILY_MARES_NEMO, 18, NULL}, {"Mares", "Nemo Apneist", DC_FAMILY_MARES_NEMO, 18, DC_TRANSPORT_SERIAL, NULL},
/* Mares Puck */ /* Mares Puck */
{"Mares", "Puck", DC_FAMILY_MARES_PUCK, 7, NULL}, {"Mares", "Puck", DC_FAMILY_MARES_PUCK, 7, DC_TRANSPORT_SERIAL, NULL},
{"Mares", "Puck Air", DC_FAMILY_MARES_PUCK, 19, NULL}, {"Mares", "Puck Air", DC_FAMILY_MARES_PUCK, 19, DC_TRANSPORT_SERIAL, NULL},
{"Mares", "Nemo Air", DC_FAMILY_MARES_PUCK, 4, NULL}, {"Mares", "Nemo Air", DC_FAMILY_MARES_PUCK, 4, DC_TRANSPORT_SERIAL, NULL},
{"Mares", "Nemo Wide", DC_FAMILY_MARES_PUCK, 1, NULL}, {"Mares", "Nemo Wide", DC_FAMILY_MARES_PUCK, 1, DC_TRANSPORT_SERIAL, NULL},
/* Mares Darwin */ /* Mares Darwin */
{"Mares", "Darwin", DC_FAMILY_MARES_DARWIN , 0, NULL}, {"Mares", "Darwin", DC_FAMILY_MARES_DARWIN , 0, DC_TRANSPORT_SERIAL, NULL},
{"Mares", "M1", DC_FAMILY_MARES_DARWIN , 0, NULL}, {"Mares", "M1", DC_FAMILY_MARES_DARWIN , 0, DC_TRANSPORT_SERIAL, NULL},
{"Mares", "M2", DC_FAMILY_MARES_DARWIN , 0, NULL}, {"Mares", "M2", DC_FAMILY_MARES_DARWIN , 0, DC_TRANSPORT_SERIAL, NULL},
{"Mares", "Darwin Air", DC_FAMILY_MARES_DARWIN , 1, NULL}, {"Mares", "Darwin Air", DC_FAMILY_MARES_DARWIN , 1, DC_TRANSPORT_SERIAL, NULL},
{"Mares", "Airlab", DC_FAMILY_MARES_DARWIN , 1, NULL}, {"Mares", "Airlab", DC_FAMILY_MARES_DARWIN , 1, DC_TRANSPORT_SERIAL, NULL},
/* Mares Icon HD */ /* Mares Icon HD */
{"Mares", "Matrix", DC_FAMILY_MARES_ICONHD , 0x0F, NULL}, {"Mares", "Matrix", DC_FAMILY_MARES_ICONHD , 0x0F, DC_TRANSPORT_SERIAL, NULL},
{"Mares", "Smart", DC_FAMILY_MARES_ICONHD , 0x000010, NULL}, {"Mares", "Smart", DC_FAMILY_MARES_ICONHD , 0x000010, DC_TRANSPORT_SERIAL, NULL},
{"Mares", "Smart Apnea", DC_FAMILY_MARES_ICONHD , 0x010010, NULL}, {"Mares", "Smart Apnea", DC_FAMILY_MARES_ICONHD , 0x010010, DC_TRANSPORT_SERIAL, NULL},
{"Mares", "Icon HD", DC_FAMILY_MARES_ICONHD , 0x14, NULL}, {"Mares", "Icon HD", DC_FAMILY_MARES_ICONHD , 0x14, DC_TRANSPORT_SERIAL, NULL},
{"Mares", "Icon HD Net Ready", DC_FAMILY_MARES_ICONHD , 0x15, NULL}, {"Mares", "Icon HD Net Ready", DC_FAMILY_MARES_ICONHD , 0x15, DC_TRANSPORT_SERIAL, NULL},
{"Mares", "Puck Pro", DC_FAMILY_MARES_ICONHD , 0x18, NULL}, {"Mares", "Puck Pro", DC_FAMILY_MARES_ICONHD , 0x18, DC_TRANSPORT_SERIAL, NULL},
{"Mares", "Nemo Wide 2", DC_FAMILY_MARES_ICONHD , 0x19, NULL}, {"Mares", "Nemo Wide 2", DC_FAMILY_MARES_ICONHD , 0x19, DC_TRANSPORT_SERIAL, NULL},
{"Mares", "Puck 2", DC_FAMILY_MARES_ICONHD , 0x1F, NULL}, {"Mares", "Puck 2", DC_FAMILY_MARES_ICONHD , 0x1F, DC_TRANSPORT_SERIAL, NULL},
{"Mares", "Quad Air", DC_FAMILY_MARES_ICONHD , 0x23, NULL}, {"Mares", "Quad Air", DC_FAMILY_MARES_ICONHD , 0x23, DC_TRANSPORT_SERIAL, NULL},
{"Mares", "Quad", DC_FAMILY_MARES_ICONHD , 0x29, NULL}, {"Mares", "Quad", DC_FAMILY_MARES_ICONHD , 0x29, DC_TRANSPORT_SERIAL, NULL},
/* Heinrichs Weikamp */ /* Heinrichs Weikamp */
{"Heinrichs Weikamp", "OSTC", DC_FAMILY_HW_OSTC, 0, NULL}, {"Heinrichs Weikamp", "OSTC", DC_FAMILY_HW_OSTC, 0, DC_TRANSPORT_SERIAL, NULL},
{"Heinrichs Weikamp", "OSTC Mk2", DC_FAMILY_HW_OSTC, 1, NULL}, {"Heinrichs Weikamp", "OSTC Mk2", DC_FAMILY_HW_OSTC, 1, DC_TRANSPORT_SERIAL, NULL},
{"Heinrichs Weikamp", "OSTC 2N", DC_FAMILY_HW_OSTC, 2, NULL}, {"Heinrichs Weikamp", "OSTC 2N", DC_FAMILY_HW_OSTC, 2, DC_TRANSPORT_SERIAL, NULL},
{"Heinrichs Weikamp", "OSTC 2C", DC_FAMILY_HW_OSTC, 3, NULL}, {"Heinrichs Weikamp", "OSTC 2C", DC_FAMILY_HW_OSTC, 3, DC_TRANSPORT_SERIAL, NULL},
{"Heinrichs Weikamp", "Frog", DC_FAMILY_HW_FROG, 0, dc_filter_hw}, {"Heinrichs Weikamp", "Frog", DC_FAMILY_HW_FROG, 0, DC_TRANSPORT_SERIAL | DC_TRANSPORT_BLUETOOTH, dc_filter_hw},
{"Heinrichs Weikamp", "OSTC 2", DC_FAMILY_HW_OSTC3, 0x11, dc_filter_hw}, {"Heinrichs Weikamp", "OSTC 2", DC_FAMILY_HW_OSTC3, 0x11, DC_TRANSPORT_SERIAL | DC_TRANSPORT_BLUETOOTH, dc_filter_hw},
{"Heinrichs Weikamp", "OSTC 2", DC_FAMILY_HW_OSTC3, 0x13, dc_filter_hw}, {"Heinrichs Weikamp", "OSTC 2", DC_FAMILY_HW_OSTC3, 0x13, DC_TRANSPORT_SERIAL | DC_TRANSPORT_BLUETOOTH, dc_filter_hw},
{"Heinrichs Weikamp", "OSTC 2", DC_FAMILY_HW_OSTC3, 0x1B, dc_filter_hw}, {"Heinrichs Weikamp", "OSTC 2", DC_FAMILY_HW_OSTC3, 0x1B, DC_TRANSPORT_SERIAL | DC_TRANSPORT_BLUETOOTH, dc_filter_hw},
{"Heinrichs Weikamp", "OSTC 3", DC_FAMILY_HW_OSTC3, 0x0A, dc_filter_hw}, {"Heinrichs Weikamp", "OSTC 3", DC_FAMILY_HW_OSTC3, 0x0A, DC_TRANSPORT_SERIAL, dc_filter_hw},
{"Heinrichs Weikamp", "OSTC Plus", DC_FAMILY_HW_OSTC3, 0x13, dc_filter_hw}, {"Heinrichs Weikamp", "OSTC Plus", DC_FAMILY_HW_OSTC3, 0x13, DC_TRANSPORT_SERIAL | DC_TRANSPORT_BLUETOOTH, dc_filter_hw},
{"Heinrichs Weikamp", "OSTC Plus", DC_FAMILY_HW_OSTC3, 0x1A, dc_filter_hw}, {"Heinrichs Weikamp", "OSTC Plus", DC_FAMILY_HW_OSTC3, 0x1A, DC_TRANSPORT_SERIAL | DC_TRANSPORT_BLUETOOTH, dc_filter_hw},
{"Heinrichs Weikamp", "OSTC 4", DC_FAMILY_HW_OSTC3, 0x3B, dc_filter_hw}, {"Heinrichs Weikamp", "OSTC 4", DC_FAMILY_HW_OSTC3, 0x3B, DC_TRANSPORT_SERIAL | DC_TRANSPORT_BLUETOOTH, dc_filter_hw},
{"Heinrichs Weikamp", "OSTC cR", DC_FAMILY_HW_OSTC3, 0x05, dc_filter_hw}, {"Heinrichs Weikamp", "OSTC cR", DC_FAMILY_HW_OSTC3, 0x05, DC_TRANSPORT_SERIAL, dc_filter_hw},
{"Heinrichs Weikamp", "OSTC cR", DC_FAMILY_HW_OSTC3, 0x07, dc_filter_hw}, {"Heinrichs Weikamp", "OSTC cR", DC_FAMILY_HW_OSTC3, 0x07, DC_TRANSPORT_SERIAL, dc_filter_hw},
{"Heinrichs Weikamp", "OSTC Sport", DC_FAMILY_HW_OSTC3, 0x12, dc_filter_hw}, {"Heinrichs Weikamp", "OSTC Sport", DC_FAMILY_HW_OSTC3, 0x12, DC_TRANSPORT_SERIAL | DC_TRANSPORT_BLUETOOTH, dc_filter_hw},
{"Heinrichs Weikamp", "OSTC Sport", DC_FAMILY_HW_OSTC3, 0x13, dc_filter_hw}, {"Heinrichs Weikamp", "OSTC Sport", DC_FAMILY_HW_OSTC3, 0x13, DC_TRANSPORT_SERIAL | DC_TRANSPORT_BLUETOOTH, dc_filter_hw},
{"Heinrichs Weikamp", "OSTC 2 TR", DC_FAMILY_HW_OSTC3, 0x33, dc_filter_hw}, {"Heinrichs Weikamp", "OSTC 2 TR", DC_FAMILY_HW_OSTC3, 0x33, DC_TRANSPORT_SERIAL | DC_TRANSPORT_BLUETOOTH, dc_filter_hw},
/* Cressi Edy */ /* Cressi Edy */
{"Tusa", "IQ-700", DC_FAMILY_CRESSI_EDY, 0x05, NULL}, {"Tusa", "IQ-700", DC_FAMILY_CRESSI_EDY, 0x05, DC_TRANSPORT_SERIAL, NULL},
{"Cressi", "Edy", DC_FAMILY_CRESSI_EDY, 0x08, NULL}, {"Cressi", "Edy", DC_FAMILY_CRESSI_EDY, 0x08, DC_TRANSPORT_SERIAL, NULL},
/* Cressi Leonardo */ /* Cressi Leonardo */
{"Cressi", "Leonardo", DC_FAMILY_CRESSI_LEONARDO, 1, NULL}, {"Cressi", "Leonardo", DC_FAMILY_CRESSI_LEONARDO, 1, DC_TRANSPORT_SERIAL, NULL},
{"Cressi", "Giotto", DC_FAMILY_CRESSI_LEONARDO, 4, NULL}, {"Cressi", "Giotto", DC_FAMILY_CRESSI_LEONARDO, 4, DC_TRANSPORT_SERIAL, NULL},
{"Cressi", "Newton", DC_FAMILY_CRESSI_LEONARDO, 5, NULL}, {"Cressi", "Newton", DC_FAMILY_CRESSI_LEONARDO, 5, DC_TRANSPORT_SERIAL, NULL},
{"Cressi", "Drake", DC_FAMILY_CRESSI_LEONARDO, 6, NULL}, {"Cressi", "Drake", DC_FAMILY_CRESSI_LEONARDO, 6, DC_TRANSPORT_SERIAL, NULL},
/* Zeagle N2iTiON3 */ /* Zeagle N2iTiON3 */
{"Zeagle", "N2iTiON3", DC_FAMILY_ZEAGLE_N2ITION3, 0, NULL}, {"Zeagle", "N2iTiON3", DC_FAMILY_ZEAGLE_N2ITION3, 0, DC_TRANSPORT_SERIAL, NULL},
{"Apeks", "Quantum X", DC_FAMILY_ZEAGLE_N2ITION3, 0, NULL}, {"Apeks", "Quantum X", DC_FAMILY_ZEAGLE_N2ITION3, 0, DC_TRANSPORT_SERIAL, NULL},
{"Dive Rite", "NiTek Trio", DC_FAMILY_ZEAGLE_N2ITION3, 0, NULL}, {"Dive Rite", "NiTek Trio", DC_FAMILY_ZEAGLE_N2ITION3, 0, DC_TRANSPORT_SERIAL, NULL},
{"Scubapro", "XTender 5", DC_FAMILY_ZEAGLE_N2ITION3, 0, NULL}, {"Scubapro", "XTender 5", DC_FAMILY_ZEAGLE_N2ITION3, 0, DC_TRANSPORT_SERIAL, NULL},
/* Atomic Aquatics Cobalt */ /* Atomic Aquatics Cobalt */
#ifdef HAVE_LIBUSB {"Atomic Aquatics", "Cobalt", DC_FAMILY_ATOMICS_COBALT, 0, DC_TRANSPORT_USB, NULL},
{"Atomic Aquatics", "Cobalt", DC_FAMILY_ATOMICS_COBALT, 0, NULL}, {"Atomic Aquatics", "Cobalt 2", DC_FAMILY_ATOMICS_COBALT, 2, DC_TRANSPORT_USB, NULL},
{"Atomic Aquatics", "Cobalt 2", DC_FAMILY_ATOMICS_COBALT, 2, NULL},
#endif
/* Shearwater Predator */ /* Shearwater Predator */
{"Shearwater", "Predator", DC_FAMILY_SHEARWATER_PREDATOR, 2, dc_filter_shearwater}, {"Shearwater", "Predator", DC_FAMILY_SHEARWATER_PREDATOR, 2, DC_TRANSPORT_SERIAL | DC_TRANSPORT_BLUETOOTH, dc_filter_shearwater},
/* Shearwater Petrel */ /* Shearwater Petrel */
{"Shearwater", "Petrel", DC_FAMILY_SHEARWATER_PETREL, 3, dc_filter_shearwater}, {"Shearwater", "Petrel", DC_FAMILY_SHEARWATER_PETREL, 3, DC_TRANSPORT_SERIAL | DC_TRANSPORT_BLUETOOTH, dc_filter_shearwater},
{"Shearwater", "Petrel 2", DC_FAMILY_SHEARWATER_PETREL, 3, dc_filter_shearwater}, {"Shearwater", "Petrel 2", DC_FAMILY_SHEARWATER_PETREL, 3, DC_TRANSPORT_SERIAL | DC_TRANSPORT_BLUETOOTH, dc_filter_shearwater},
{"Shearwater", "Nerd", DC_FAMILY_SHEARWATER_PETREL, 4, dc_filter_shearwater}, {"Shearwater", "Nerd", DC_FAMILY_SHEARWATER_PETREL, 4, DC_TRANSPORT_SERIAL | DC_TRANSPORT_BLUETOOTH, dc_filter_shearwater},
{"Shearwater", "Perdix", DC_FAMILY_SHEARWATER_PETREL, 5, dc_filter_shearwater}, {"Shearwater", "Perdix", DC_FAMILY_SHEARWATER_PETREL, 5, DC_TRANSPORT_SERIAL | DC_TRANSPORT_BLUETOOTH, dc_filter_shearwater},
{"Shearwater", "Perdix AI", DC_FAMILY_SHEARWATER_PETREL, 6, dc_filter_shearwater}, {"Shearwater", "Perdix AI", DC_FAMILY_SHEARWATER_PETREL, 6, DC_TRANSPORT_NONE, dc_filter_shearwater},
{"Shearwater", "Nerd 2", DC_FAMILY_SHEARWATER_PETREL, 7, dc_filter_shearwater}, {"Shearwater", "Nerd 2", DC_FAMILY_SHEARWATER_PETREL, 7, DC_TRANSPORT_NONE, dc_filter_shearwater},
/* Dive Rite NiTek Q */ /* Dive Rite NiTek Q */
{"Dive Rite", "NiTek Q", DC_FAMILY_DIVERITE_NITEKQ, 0, NULL}, {"Dive Rite", "NiTek Q", DC_FAMILY_DIVERITE_NITEKQ, 0, DC_TRANSPORT_SERIAL, NULL},
/* Citizen Hyper Aqualand */ /* Citizen Hyper Aqualand */
{"Citizen", "Hyper Aqualand", DC_FAMILY_CITIZEN_AQUALAND, 0, NULL}, {"Citizen", "Hyper Aqualand", DC_FAMILY_CITIZEN_AQUALAND, 0, DC_TRANSPORT_SERIAL, NULL},
/* DiveSystem/Ratio iDive */ /* DiveSystem/Ratio iDive */
{"DiveSystem", "Orca", DC_FAMILY_DIVESYSTEM_IDIVE, 0x02, NULL}, {"DiveSystem", "Orca", DC_FAMILY_DIVESYSTEM_IDIVE, 0x02, DC_TRANSPORT_SERIAL, NULL},
{"DiveSystem", "iDive Pro", DC_FAMILY_DIVESYSTEM_IDIVE, 0x03, NULL}, {"DiveSystem", "iDive Pro", DC_FAMILY_DIVESYSTEM_IDIVE, 0x03, DC_TRANSPORT_SERIAL, NULL},
{"DiveSystem", "iDive DAN", DC_FAMILY_DIVESYSTEM_IDIVE, 0x04, NULL}, {"DiveSystem", "iDive DAN", DC_FAMILY_DIVESYSTEM_IDIVE, 0x04, DC_TRANSPORT_SERIAL, NULL},
{"DiveSystem", "iDive Tech", DC_FAMILY_DIVESYSTEM_IDIVE, 0x05, NULL}, {"DiveSystem", "iDive Tech", DC_FAMILY_DIVESYSTEM_IDIVE, 0x05, DC_TRANSPORT_SERIAL, NULL},
{"DiveSystem", "iDive Reb", DC_FAMILY_DIVESYSTEM_IDIVE, 0x06, NULL}, {"DiveSystem", "iDive Reb", DC_FAMILY_DIVESYSTEM_IDIVE, 0x06, DC_TRANSPORT_SERIAL, NULL},
{"DiveSystem", "iDive Stealth", DC_FAMILY_DIVESYSTEM_IDIVE, 0x07, NULL}, {"DiveSystem", "iDive Stealth", DC_FAMILY_DIVESYSTEM_IDIVE, 0x07, DC_TRANSPORT_SERIAL, NULL},
{"DiveSystem", "iDive Free", DC_FAMILY_DIVESYSTEM_IDIVE, 0x08, NULL}, {"DiveSystem", "iDive Free", DC_FAMILY_DIVESYSTEM_IDIVE, 0x08, DC_TRANSPORT_SERIAL, NULL},
{"DiveSystem", "iDive Easy", DC_FAMILY_DIVESYSTEM_IDIVE, 0x09, NULL}, {"DiveSystem", "iDive Easy", DC_FAMILY_DIVESYSTEM_IDIVE, 0x09, DC_TRANSPORT_SERIAL, NULL},
{"DiveSystem", "iDive X3M", DC_FAMILY_DIVESYSTEM_IDIVE, 0x0A, NULL}, {"DiveSystem", "iDive X3M", DC_FAMILY_DIVESYSTEM_IDIVE, 0x0A, DC_TRANSPORT_SERIAL, NULL},
{"DiveSystem", "iDive Deep", DC_FAMILY_DIVESYSTEM_IDIVE, 0x0B, NULL}, {"DiveSystem", "iDive Deep", DC_FAMILY_DIVESYSTEM_IDIVE, 0x0B, DC_TRANSPORT_SERIAL, NULL},
{"Ratio", "iX3M Easy", DC_FAMILY_DIVESYSTEM_IDIVE, 0x22, NULL}, {"Ratio", "iX3M Easy", DC_FAMILY_DIVESYSTEM_IDIVE, 0x22, DC_TRANSPORT_SERIAL, NULL},
{"Ratio", "iX3M Deep", DC_FAMILY_DIVESYSTEM_IDIVE, 0x23, NULL}, {"Ratio", "iX3M Deep", DC_FAMILY_DIVESYSTEM_IDIVE, 0x23, DC_TRANSPORT_SERIAL, NULL},
{"Ratio", "iX3M Tech+", DC_FAMILY_DIVESYSTEM_IDIVE, 0x24, NULL}, {"Ratio", "iX3M Tech+", DC_FAMILY_DIVESYSTEM_IDIVE, 0x24, DC_TRANSPORT_SERIAL, NULL},
{"Ratio", "iX3M Reb", DC_FAMILY_DIVESYSTEM_IDIVE, 0x25, NULL}, {"Ratio", "iX3M Reb", DC_FAMILY_DIVESYSTEM_IDIVE, 0x25, DC_TRANSPORT_SERIAL, NULL},
{"Ratio", "iX3M Pro Easy", DC_FAMILY_DIVESYSTEM_IDIVE, 0x32, NULL}, {"Ratio", "iX3M Pro Easy", DC_FAMILY_DIVESYSTEM_IDIVE, 0x32, DC_TRANSPORT_SERIAL, NULL},
{"Ratio", "iX3M Pro Deep", DC_FAMILY_DIVESYSTEM_IDIVE, 0x34, NULL}, {"Ratio", "iX3M Pro Deep", DC_FAMILY_DIVESYSTEM_IDIVE, 0x34, DC_TRANSPORT_SERIAL, NULL},
{"Ratio", "iX3M Pro Tech+",DC_FAMILY_DIVESYSTEM_IDIVE, 0x35, NULL}, {"Ratio", "iX3M Pro Tech+",DC_FAMILY_DIVESYSTEM_IDIVE, 0x35, DC_TRANSPORT_SERIAL, NULL},
{"Ratio", "iDive Free", DC_FAMILY_DIVESYSTEM_IDIVE, 0x40, NULL}, {"Ratio", "iDive Free", DC_FAMILY_DIVESYSTEM_IDIVE, 0x40, DC_TRANSPORT_SERIAL, NULL},
{"Ratio", "iDive Easy", DC_FAMILY_DIVESYSTEM_IDIVE, 0x42, NULL}, {"Ratio", "iDive Easy", DC_FAMILY_DIVESYSTEM_IDIVE, 0x42, DC_TRANSPORT_SERIAL, NULL},
{"Ratio", "iDive Deep", DC_FAMILY_DIVESYSTEM_IDIVE, 0x44, NULL}, {"Ratio", "iDive Deep", DC_FAMILY_DIVESYSTEM_IDIVE, 0x44, DC_TRANSPORT_SERIAL, NULL},
{"Ratio", "iDive Tech+", DC_FAMILY_DIVESYSTEM_IDIVE, 0x45, NULL}, {"Ratio", "iDive Tech+", DC_FAMILY_DIVESYSTEM_IDIVE, 0x45, DC_TRANSPORT_SERIAL, NULL},
{"Seac", "Jack", DC_FAMILY_DIVESYSTEM_IDIVE, 0x1000, NULL}, {"Seac", "Jack", DC_FAMILY_DIVESYSTEM_IDIVE, 0x1000, DC_TRANSPORT_SERIAL, NULL},
/* Cochran Commander */ /* Cochran Commander */
{"Cochran", "Commander TM", DC_FAMILY_COCHRAN_COMMANDER, 0, NULL}, {"Cochran", "Commander TM", DC_FAMILY_COCHRAN_COMMANDER, 0, DC_TRANSPORT_SERIAL, NULL},
{"Cochran", "Commander I", DC_FAMILY_COCHRAN_COMMANDER, 1, NULL}, {"Cochran", "Commander I", DC_FAMILY_COCHRAN_COMMANDER, 1, DC_TRANSPORT_SERIAL, NULL},
{"Cochran", "Commander II", DC_FAMILY_COCHRAN_COMMANDER, 2, NULL}, {"Cochran", "Commander II", DC_FAMILY_COCHRAN_COMMANDER, 2, DC_TRANSPORT_SERIAL, NULL},
{"Cochran", "EMC-14", DC_FAMILY_COCHRAN_COMMANDER, 3, NULL}, {"Cochran", "EMC-14", DC_FAMILY_COCHRAN_COMMANDER, 3, DC_TRANSPORT_SERIAL, NULL},
{"Cochran", "EMC-16", DC_FAMILY_COCHRAN_COMMANDER, 4, NULL}, {"Cochran", "EMC-16", DC_FAMILY_COCHRAN_COMMANDER, 4, DC_TRANSPORT_SERIAL, NULL},
{"Cochran", "EMC-20H", DC_FAMILY_COCHRAN_COMMANDER, 5, NULL}, {"Cochran", "EMC-20H", DC_FAMILY_COCHRAN_COMMANDER, 5, DC_TRANSPORT_SERIAL, NULL},
}; };
static int static int
@ -530,22 +503,13 @@ dc_descriptor_get_model (dc_descriptor_t *descriptor)
return descriptor->model; return descriptor->model;
} }
dc_transport_t unsigned int
dc_descriptor_get_transport (dc_descriptor_t *descriptor) dc_descriptor_get_transports (dc_descriptor_t *descriptor)
{ {
if (descriptor == NULL) if (descriptor == NULL)
return DC_TRANSPORT_NONE; return DC_TRANSPORT_NONE;
if (descriptor->type == DC_FAMILY_ATOMICS_COBALT) return descriptor->transports;
return DC_TRANSPORT_USB;
else if (descriptor->type == DC_FAMILY_SUUNTO_EONSTEEL)
return DC_TRANSPORT_USBHID;
else if (descriptor->type == DC_FAMILY_UWATEC_G2)
return DC_TRANSPORT_USBHID;
else if (descriptor->type == DC_FAMILY_UWATEC_SMART)
return DC_TRANSPORT_IRDA;
else
return DC_TRANSPORT_SERIAL;
} }
dc_filter_t dc_filter_t

View File

@ -100,7 +100,7 @@ dc_device_deallocate (dc_device_t *device)
} }
dc_status_t dc_status_t
dc_device_open (dc_device_t **out, dc_context_t *context, dc_descriptor_t *descriptor, const char *name) dc_device_open (dc_device_t **out, dc_context_t *context, dc_descriptor_t *descriptor, dc_iostream_t *iostream)
{ {
dc_status_t rc = DC_STATUS_SUCCESS; dc_status_t rc = DC_STATUS_SUCCESS;
dc_device_t *device = NULL; dc_device_t *device = NULL;
@ -110,106 +110,106 @@ dc_device_open (dc_device_t **out, dc_context_t *context, dc_descriptor_t *descr
switch (dc_descriptor_get_type (descriptor)) { switch (dc_descriptor_get_type (descriptor)) {
case DC_FAMILY_SUUNTO_SOLUTION: case DC_FAMILY_SUUNTO_SOLUTION:
rc = suunto_solution_device_open (&device, context, name); rc = suunto_solution_device_open (&device, context, iostream);
break; break;
case DC_FAMILY_SUUNTO_EON: case DC_FAMILY_SUUNTO_EON:
rc = suunto_eon_device_open (&device, context, name); rc = suunto_eon_device_open (&device, context, iostream);
break; break;
case DC_FAMILY_SUUNTO_VYPER: case DC_FAMILY_SUUNTO_VYPER:
rc = suunto_vyper_device_open (&device, context, name); rc = suunto_vyper_device_open (&device, context, iostream);
break; break;
case DC_FAMILY_SUUNTO_VYPER2: case DC_FAMILY_SUUNTO_VYPER2:
rc = suunto_vyper2_device_open (&device, context, name); rc = suunto_vyper2_device_open (&device, context, iostream);
break; break;
case DC_FAMILY_SUUNTO_D9: case DC_FAMILY_SUUNTO_D9:
rc = suunto_d9_device_open (&device, context, name, dc_descriptor_get_model (descriptor)); rc = suunto_d9_device_open (&device, context, iostream, dc_descriptor_get_model (descriptor));
break; break;
case DC_FAMILY_SUUNTO_EONSTEEL: case DC_FAMILY_SUUNTO_EONSTEEL:
rc = suunto_eonsteel_device_open (&device, context, dc_descriptor_get_model (descriptor)); rc = suunto_eonsteel_device_open (&device, context, iostream, dc_descriptor_get_model (descriptor));
break; break;
case DC_FAMILY_UWATEC_ALADIN: case DC_FAMILY_UWATEC_ALADIN:
rc = uwatec_aladin_device_open (&device, context, name); rc = uwatec_aladin_device_open (&device, context, iostream);
break; break;
case DC_FAMILY_UWATEC_MEMOMOUSE: case DC_FAMILY_UWATEC_MEMOMOUSE:
rc = uwatec_memomouse_device_open (&device, context, name); rc = uwatec_memomouse_device_open (&device, context, iostream);
break; break;
case DC_FAMILY_UWATEC_SMART: case DC_FAMILY_UWATEC_SMART:
rc = uwatec_smart_device_open (&device, context); rc = uwatec_smart_device_open (&device, context, iostream);
break; break;
case DC_FAMILY_UWATEC_MERIDIAN: case DC_FAMILY_UWATEC_MERIDIAN:
rc = uwatec_meridian_device_open (&device, context, name); rc = uwatec_meridian_device_open (&device, context, iostream);
break; break;
case DC_FAMILY_UWATEC_G2: case DC_FAMILY_UWATEC_G2:
rc = uwatec_g2_device_open (&device, context, dc_descriptor_get_model (descriptor)); rc = uwatec_g2_device_open (&device, context, iostream, dc_descriptor_get_model (descriptor));
break; break;
case DC_FAMILY_REEFNET_SENSUS: case DC_FAMILY_REEFNET_SENSUS:
rc = reefnet_sensus_device_open (&device, context, name); rc = reefnet_sensus_device_open (&device, context, iostream);
break; break;
case DC_FAMILY_REEFNET_SENSUSPRO: case DC_FAMILY_REEFNET_SENSUSPRO:
rc = reefnet_sensuspro_device_open (&device, context, name); rc = reefnet_sensuspro_device_open (&device, context, iostream);
break; break;
case DC_FAMILY_REEFNET_SENSUSULTRA: case DC_FAMILY_REEFNET_SENSUSULTRA:
rc = reefnet_sensusultra_device_open (&device, context, name); rc = reefnet_sensusultra_device_open (&device, context, iostream);
break; break;
case DC_FAMILY_OCEANIC_VTPRO: case DC_FAMILY_OCEANIC_VTPRO:
rc = oceanic_vtpro_device_open (&device, context, name, dc_descriptor_get_model (descriptor)); rc = oceanic_vtpro_device_open (&device, context, iostream, dc_descriptor_get_model (descriptor));
break; break;
case DC_FAMILY_OCEANIC_VEO250: case DC_FAMILY_OCEANIC_VEO250:
rc = oceanic_veo250_device_open (&device, context, name); rc = oceanic_veo250_device_open (&device, context, iostream);
break; break;
case DC_FAMILY_OCEANIC_ATOM2: case DC_FAMILY_OCEANIC_ATOM2:
rc = oceanic_atom2_device_open (&device, context, name, dc_descriptor_get_model (descriptor)); rc = oceanic_atom2_device_open (&device, context, iostream, dc_descriptor_get_model (descriptor));
break; break;
case DC_FAMILY_MARES_NEMO: case DC_FAMILY_MARES_NEMO:
rc = mares_nemo_device_open (&device, context, name); rc = mares_nemo_device_open (&device, context, iostream);
break; break;
case DC_FAMILY_MARES_PUCK: case DC_FAMILY_MARES_PUCK:
rc = mares_puck_device_open (&device, context, name); rc = mares_puck_device_open (&device, context, iostream);
break; break;
case DC_FAMILY_MARES_DARWIN: case DC_FAMILY_MARES_DARWIN:
rc = mares_darwin_device_open (&device, context, name, dc_descriptor_get_model (descriptor)); rc = mares_darwin_device_open (&device, context, iostream, dc_descriptor_get_model (descriptor));
break; break;
case DC_FAMILY_MARES_ICONHD: case DC_FAMILY_MARES_ICONHD:
rc = mares_iconhd_device_open (&device, context, name); rc = mares_iconhd_device_open (&device, context, iostream);
break; break;
case DC_FAMILY_HW_OSTC: case DC_FAMILY_HW_OSTC:
rc = hw_ostc_device_open (&device, context, name); rc = hw_ostc_device_open (&device, context, iostream);
break; break;
case DC_FAMILY_HW_FROG: case DC_FAMILY_HW_FROG:
rc = hw_frog_device_open (&device, context, name); rc = hw_frog_device_open (&device, context, iostream);
break; break;
case DC_FAMILY_HW_OSTC3: case DC_FAMILY_HW_OSTC3:
rc = hw_ostc3_device_open (&device, context, name); rc = hw_ostc3_device_open (&device, context, iostream);
break; break;
case DC_FAMILY_CRESSI_EDY: case DC_FAMILY_CRESSI_EDY:
rc = cressi_edy_device_open (&device, context, name); rc = cressi_edy_device_open (&device, context, iostream);
break; break;
case DC_FAMILY_CRESSI_LEONARDO: case DC_FAMILY_CRESSI_LEONARDO:
rc = cressi_leonardo_device_open (&device, context, name); rc = cressi_leonardo_device_open (&device, context, iostream);
break; break;
case DC_FAMILY_ZEAGLE_N2ITION3: case DC_FAMILY_ZEAGLE_N2ITION3:
rc = zeagle_n2ition3_device_open (&device, context, name); rc = zeagle_n2ition3_device_open (&device, context, iostream);
break; break;
case DC_FAMILY_ATOMICS_COBALT: case DC_FAMILY_ATOMICS_COBALT:
rc = atomics_cobalt_device_open (&device, context); rc = atomics_cobalt_device_open (&device, context);
break; break;
case DC_FAMILY_SHEARWATER_PREDATOR: case DC_FAMILY_SHEARWATER_PREDATOR:
rc = shearwater_predator_device_open (&device, context, name); rc = shearwater_predator_device_open (&device, context, iostream);
break; break;
case DC_FAMILY_SHEARWATER_PETREL: case DC_FAMILY_SHEARWATER_PETREL:
rc = shearwater_petrel_device_open (&device, context, name); rc = shearwater_petrel_device_open (&device, context, iostream);
break; break;
case DC_FAMILY_DIVERITE_NITEKQ: case DC_FAMILY_DIVERITE_NITEKQ:
rc = diverite_nitekq_device_open (&device, context, name); rc = diverite_nitekq_device_open (&device, context, iostream);
break; break;
case DC_FAMILY_CITIZEN_AQUALAND: case DC_FAMILY_CITIZEN_AQUALAND:
rc = citizen_aqualand_device_open (&device, context, name); rc = citizen_aqualand_device_open (&device, context, iostream);
break; break;
case DC_FAMILY_DIVESYSTEM_IDIVE: case DC_FAMILY_DIVESYSTEM_IDIVE:
rc = divesystem_idive_device_open (&device, context, name, dc_descriptor_get_model (descriptor)); rc = divesystem_idive_device_open (&device, context, iostream, dc_descriptor_get_model (descriptor));
break; break;
case DC_FAMILY_COCHRAN_COMMANDER: case DC_FAMILY_COCHRAN_COMMANDER:
rc = cochran_commander_device_open (&device, context, name); rc = cochran_commander_device_open (&device, context, iostream);
break; break;
default: default:
return DC_STATUS_INVALIDARGS; return DC_STATUS_INVALIDARGS;

View File

@ -27,7 +27,6 @@
#include "context-private.h" #include "context-private.h"
#include "device-private.h" #include "device-private.h"
#include "checksum.h" #include "checksum.h"
#include "serial.h"
#include "array.h" #include "array.h"
#define ISINSTANCE(device) dc_device_isinstance((device), &diverite_nitekq_device_vtable) #define ISINSTANCE(device) dc_device_isinstance((device), &diverite_nitekq_device_vtable)
@ -148,7 +147,7 @@ diverite_nitekq_handshake (diverite_nitekq_device_t *device)
dc_status_t dc_status_t
diverite_nitekq_device_open (dc_device_t **out, dc_context_t *context, const char *name) diverite_nitekq_device_open (dc_device_t **out, dc_context_t *context, dc_iostream_t *iostream)
{ {
dc_status_t status = DC_STATUS_SUCCESS; dc_status_t status = DC_STATUS_SUCCESS;
diverite_nitekq_device_t *device = NULL; diverite_nitekq_device_t *device = NULL;
@ -164,28 +163,21 @@ diverite_nitekq_device_open (dc_device_t **out, dc_context_t *context, const cha
} }
// Set the default values. // Set the default values.
device->iostream = NULL; device->iostream = iostream;
memset (device->fingerprint, 0, sizeof (device->fingerprint)); memset (device->fingerprint, 0, sizeof (device->fingerprint));
// Open the device.
status = dc_serial_open (&device->iostream, context, name);
if (status != DC_STATUS_SUCCESS) {
ERROR (context, "Failed to open the serial port.");
goto error_free;
}
// Set the serial communication protocol (9600 8N1). // Set the serial communication protocol (9600 8N1).
status = dc_iostream_configure (device->iostream, 9600, 8, DC_PARITY_NONE, DC_STOPBITS_ONE, DC_FLOWCONTROL_NONE); status = dc_iostream_configure (device->iostream, 9600, 8, DC_PARITY_NONE, DC_STOPBITS_ONE, DC_FLOWCONTROL_NONE);
if (status != DC_STATUS_SUCCESS) { if (status != DC_STATUS_SUCCESS) {
ERROR (context, "Failed to set the terminal attributes."); ERROR (context, "Failed to set the terminal attributes.");
goto error_close; goto error_free;
} }
// Set the timeout for receiving data (1000ms). // Set the timeout for receiving data (1000ms).
status = dc_iostream_set_timeout (device->iostream, 1000); status = dc_iostream_set_timeout (device->iostream, 1000);
if (status != DC_STATUS_SUCCESS) { if (status != DC_STATUS_SUCCESS) {
ERROR (context, "Failed to set the timeout."); ERROR (context, "Failed to set the timeout.");
goto error_close; goto error_free;
} }
// Make sure everything is in a sane state. // Make sure everything is in a sane state.
@ -196,15 +188,13 @@ diverite_nitekq_device_open (dc_device_t **out, dc_context_t *context, const cha
status = diverite_nitekq_handshake (device); status = diverite_nitekq_handshake (device);
if (status != DC_STATUS_SUCCESS) { if (status != DC_STATUS_SUCCESS) {
ERROR (context, "Failed to handshake."); ERROR (context, "Failed to handshake.");
goto error_close; goto error_free;
} }
*out = (dc_device_t*) device; *out = (dc_device_t*) device;
return DC_STATUS_SUCCESS; return DC_STATUS_SUCCESS;
error_close:
dc_iostream_close (device->iostream);
error_free: error_free:
dc_device_deallocate ((dc_device_t *) device); dc_device_deallocate ((dc_device_t *) device);
return status; return status;
@ -224,12 +214,6 @@ diverite_nitekq_device_close (dc_device_t *abstract)
dc_status_set_error(&status, rc); dc_status_set_error(&status, rc);
} }
// Close the device.
rc = dc_iostream_close (device->iostream);
if (rc != DC_STATUS_SUCCESS) {
dc_status_set_error(&status, rc);
}
return status; return status;
} }

View File

@ -23,6 +23,7 @@
#define DIVERITE_NITEKQ_H #define DIVERITE_NITEKQ_H
#include <libdivecomputer/context.h> #include <libdivecomputer/context.h>
#include <libdivecomputer/iostream.h>
#include <libdivecomputer/device.h> #include <libdivecomputer/device.h>
#include <libdivecomputer/parser.h> #include <libdivecomputer/parser.h>
@ -31,7 +32,7 @@ extern "C" {
#endif /* __cplusplus */ #endif /* __cplusplus */
dc_status_t dc_status_t
diverite_nitekq_device_open (dc_device_t **device, dc_context_t *context, const char *name); diverite_nitekq_device_open (dc_device_t **device, dc_context_t *context, dc_iostream_t *iostream);
dc_status_t dc_status_t
diverite_nitekq_parser_create (dc_parser_t **parser, dc_context_t *context); diverite_nitekq_parser_create (dc_parser_t **parser, dc_context_t *context);

View File

@ -25,7 +25,6 @@
#include "divesystem_idive.h" #include "divesystem_idive.h"
#include "context-private.h" #include "context-private.h"
#include "device-private.h" #include "device-private.h"
#include "serial.h"
#include "checksum.h" #include "checksum.h"
#include "array.h" #include "array.h"
@ -76,7 +75,6 @@ typedef struct divesystem_idive_device_t {
static dc_status_t divesystem_idive_device_set_fingerprint (dc_device_t *abstract, const unsigned char data[], unsigned int size); static dc_status_t divesystem_idive_device_set_fingerprint (dc_device_t *abstract, const unsigned char data[], unsigned int size);
static dc_status_t divesystem_idive_device_foreach (dc_device_t *abstract, dc_dive_callback_t callback, void *userdata); static dc_status_t divesystem_idive_device_foreach (dc_device_t *abstract, dc_dive_callback_t callback, void *userdata);
static dc_status_t divesystem_idive_device_close (dc_device_t *abstract);
static const dc_device_vtable_t divesystem_idive_device_vtable = { static const dc_device_vtable_t divesystem_idive_device_vtable = {
sizeof(divesystem_idive_device_t), sizeof(divesystem_idive_device_t),
@ -87,7 +85,7 @@ static const dc_device_vtable_t divesystem_idive_device_vtable = {
NULL, /* dump */ NULL, /* dump */
divesystem_idive_device_foreach, /* foreach */ divesystem_idive_device_foreach, /* foreach */
NULL, /* timesync */ NULL, /* timesync */
divesystem_idive_device_close /* close */ NULL /* close */
}; };
static const divesystem_idive_commands_t idive = { static const divesystem_idive_commands_t idive = {
@ -115,7 +113,7 @@ static const divesystem_idive_commands_t ix3m_apos4 = {
}; };
dc_status_t dc_status_t
divesystem_idive_device_open (dc_device_t **out, dc_context_t *context, const char *name, unsigned int model) divesystem_idive_device_open (dc_device_t **out, dc_context_t *context, dc_iostream_t *iostream, unsigned int model)
{ {
dc_status_t status = DC_STATUS_SUCCESS; dc_status_t status = DC_STATUS_SUCCESS;
divesystem_idive_device_t *device = NULL; divesystem_idive_device_t *device = NULL;
@ -131,29 +129,22 @@ divesystem_idive_device_open (dc_device_t **out, dc_context_t *context, const ch
} }
// Set the default values. // Set the default values.
device->iostream = NULL; device->iostream = iostream;
memset (device->fingerprint, 0, sizeof (device->fingerprint)); memset (device->fingerprint, 0, sizeof (device->fingerprint));
device->model = model; device->model = model;
// Open the device.
status = dc_serial_open (&device->iostream, context, name);
if (status != DC_STATUS_SUCCESS) {
ERROR (context, "Failed to open the serial port.");
goto error_free;
}
// Set the serial communication protocol (115200 8N1). // Set the serial communication protocol (115200 8N1).
status = dc_iostream_configure (device->iostream, 115200, 8, DC_PARITY_NONE, DC_STOPBITS_ONE, DC_FLOWCONTROL_NONE); status = dc_iostream_configure (device->iostream, 115200, 8, DC_PARITY_NONE, DC_STOPBITS_ONE, DC_FLOWCONTROL_NONE);
if (status != DC_STATUS_SUCCESS) { if (status != DC_STATUS_SUCCESS) {
ERROR (context, "Failed to set the terminal attributes."); ERROR (context, "Failed to set the terminal attributes.");
goto error_close; goto error_free;
} }
// Set the timeout for receiving data (1000ms). // Set the timeout for receiving data (1000ms).
status = dc_iostream_set_timeout (device->iostream, 1000); status = dc_iostream_set_timeout (device->iostream, 1000);
if (status != DC_STATUS_SUCCESS) { if (status != DC_STATUS_SUCCESS) {
ERROR (context, "Failed to set the timeout."); ERROR (context, "Failed to set the timeout.");
goto error_close; goto error_free;
} }
// Make sure everything is in a sane state. // Make sure everything is in a sane state.
@ -164,31 +155,12 @@ divesystem_idive_device_open (dc_device_t **out, dc_context_t *context, const ch
return DC_STATUS_SUCCESS; return DC_STATUS_SUCCESS;
error_close:
dc_iostream_close (device->iostream);
error_free: error_free:
dc_device_deallocate ((dc_device_t *) device); dc_device_deallocate ((dc_device_t *) device);
return status; return status;
} }
static dc_status_t
divesystem_idive_device_close (dc_device_t *abstract)
{
dc_status_t status = DC_STATUS_SUCCESS;
divesystem_idive_device_t *device = (divesystem_idive_device_t*) abstract;
dc_status_t rc = DC_STATUS_SUCCESS;
// Close the device.
rc = dc_iostream_close (device->iostream);
if (rc != DC_STATUS_SUCCESS) {
dc_status_set_error(&status, rc);
}
return status;
}
static dc_status_t static dc_status_t
divesystem_idive_device_set_fingerprint (dc_device_t *abstract, const unsigned char data[], unsigned int size) divesystem_idive_device_set_fingerprint (dc_device_t *abstract, const unsigned char data[], unsigned int size)
{ {

View File

@ -23,6 +23,7 @@
#define DIVESYSTEM_IDIVE_H #define DIVESYSTEM_IDIVE_H
#include <libdivecomputer/context.h> #include <libdivecomputer/context.h>
#include <libdivecomputer/iostream.h>
#include <libdivecomputer/device.h> #include <libdivecomputer/device.h>
#include <libdivecomputer/parser.h> #include <libdivecomputer/parser.h>
@ -31,7 +32,7 @@ extern "C" {
#endif /* __cplusplus */ #endif /* __cplusplus */
dc_status_t dc_status_t
divesystem_idive_device_open (dc_device_t **device, dc_context_t *context, const char *name, unsigned int model); divesystem_idive_device_open (dc_device_t **device, dc_context_t *context, dc_iostream_t *iostream, unsigned int model);
dc_status_t dc_status_t
divesystem_idive_parser_create (dc_parser_t **parser, dc_context_t *context, unsigned int model); divesystem_idive_parser_create (dc_parser_t **parser, dc_context_t *context, unsigned int model);

View File

@ -25,7 +25,6 @@
#include "hw_frog.h" #include "hw_frog.h"
#include "context-private.h" #include "context-private.h"
#include "device-private.h" #include "device-private.h"
#include "serial.h"
#include "checksum.h" #include "checksum.h"
#include "ringbuffer.h" #include "ringbuffer.h"
#include "array.h" #include "array.h"
@ -199,7 +198,7 @@ hw_frog_transfer (hw_frog_device_t *device,
dc_status_t dc_status_t
hw_frog_device_open (dc_device_t **out, dc_context_t *context, const char *name) hw_frog_device_open (dc_device_t **out, dc_context_t *context, dc_iostream_t *iostream)
{ {
dc_status_t status = DC_STATUS_SUCCESS; dc_status_t status = DC_STATUS_SUCCESS;
hw_frog_device_t *device = NULL; hw_frog_device_t *device = NULL;
@ -215,28 +214,21 @@ hw_frog_device_open (dc_device_t **out, dc_context_t *context, const char *name)
} }
// Set the default values. // Set the default values.
device->iostream = NULL; device->iostream = iostream;
memset (device->fingerprint, 0, sizeof (device->fingerprint)); memset (device->fingerprint, 0, sizeof (device->fingerprint));
// Open the device.
status = dc_serial_open (&device->iostream, context, name);
if (status != DC_STATUS_SUCCESS) {
ERROR (context, "Failed to open the serial port.");
goto error_free;
}
// Set the serial communication protocol (115200 8N1). // Set the serial communication protocol (115200 8N1).
status = dc_iostream_configure (device->iostream, 115200, 8, DC_PARITY_NONE, DC_STOPBITS_ONE, DC_FLOWCONTROL_NONE); status = dc_iostream_configure (device->iostream, 115200, 8, DC_PARITY_NONE, DC_STOPBITS_ONE, DC_FLOWCONTROL_NONE);
if (status != DC_STATUS_SUCCESS) { if (status != DC_STATUS_SUCCESS) {
ERROR (context, "Failed to set the terminal attributes."); ERROR (context, "Failed to set the terminal attributes.");
goto error_close; goto error_free;
} }
// Set the timeout for receiving data (3000ms). // Set the timeout for receiving data (3000ms).
status = dc_iostream_set_timeout (device->iostream, 3000); status = dc_iostream_set_timeout (device->iostream, 3000);
if (status != DC_STATUS_SUCCESS) { if (status != DC_STATUS_SUCCESS) {
ERROR (context, "Failed to set the timeout."); ERROR (context, "Failed to set the timeout.");
goto error_close; goto error_free;
} }
// Make sure everything is in a sane state. // Make sure everything is in a sane state.
@ -247,15 +239,13 @@ hw_frog_device_open (dc_device_t **out, dc_context_t *context, const char *name)
status = hw_frog_transfer (device, NULL, INIT, NULL, 0, NULL, 0); status = hw_frog_transfer (device, NULL, INIT, NULL, 0, NULL, 0);
if (status != DC_STATUS_SUCCESS) { if (status != DC_STATUS_SUCCESS) {
ERROR (context, "Failed to send the command."); ERROR (context, "Failed to send the command.");
goto error_close; goto error_free;
} }
*out = (dc_device_t *) device; *out = (dc_device_t *) device;
return DC_STATUS_SUCCESS; return DC_STATUS_SUCCESS;
error_close:
dc_iostream_close (device->iostream);
error_free: error_free:
dc_device_deallocate ((dc_device_t *) device); dc_device_deallocate ((dc_device_t *) device);
return status; return status;
@ -276,12 +266,6 @@ hw_frog_device_close (dc_device_t *abstract)
dc_status_set_error(&status, rc); dc_status_set_error(&status, rc);
} }
// Close the device.
rc = dc_iostream_close (device->iostream);
if (rc != DC_STATUS_SUCCESS) {
dc_status_set_error(&status, rc);
}
return status; return status;
} }

View File

@ -23,6 +23,7 @@
#define HW_FROG_H #define HW_FROG_H
#include <libdivecomputer/context.h> #include <libdivecomputer/context.h>
#include <libdivecomputer/iostream.h>
#include <libdivecomputer/device.h> #include <libdivecomputer/device.h>
#include <libdivecomputer/parser.h> #include <libdivecomputer/parser.h>
#include <libdivecomputer/hw_frog.h> #include <libdivecomputer/hw_frog.h>
@ -32,7 +33,7 @@ extern "C" {
#endif /* __cplusplus */ #endif /* __cplusplus */
dc_status_t dc_status_t
hw_frog_device_open (dc_device_t **device, dc_context_t *context, const char *name); hw_frog_device_open (dc_device_t **device, dc_context_t *context, dc_iostream_t *iostream);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -25,7 +25,6 @@
#include "hw_ostc.h" #include "hw_ostc.h"
#include "context-private.h" #include "context-private.h"
#include "device-private.h" #include "device-private.h"
#include "serial.h"
#include "checksum.h" #include "checksum.h"
#include "array.h" #include "array.h"
#include "ihex.h" #include "ihex.h"
@ -71,7 +70,6 @@ static dc_status_t hw_ostc_device_set_fingerprint (dc_device_t *abstract, const
static dc_status_t hw_ostc_device_dump (dc_device_t *abstract, dc_buffer_t *buffer); static dc_status_t hw_ostc_device_dump (dc_device_t *abstract, dc_buffer_t *buffer);
static dc_status_t hw_ostc_device_foreach (dc_device_t *abstract, dc_dive_callback_t callback, void *userdata); static dc_status_t hw_ostc_device_foreach (dc_device_t *abstract, dc_dive_callback_t callback, void *userdata);
static dc_status_t hw_ostc_device_timesync (dc_device_t *abstract, const dc_datetime_t *datetime); static dc_status_t hw_ostc_device_timesync (dc_device_t *abstract, const dc_datetime_t *datetime);
static dc_status_t hw_ostc_device_close (dc_device_t *abstract);
static const dc_device_vtable_t hw_ostc_device_vtable = { static const dc_device_vtable_t hw_ostc_device_vtable = {
sizeof(hw_ostc_device_t), sizeof(hw_ostc_device_t),
@ -82,7 +80,7 @@ static const dc_device_vtable_t hw_ostc_device_vtable = {
hw_ostc_device_dump, /* dump */ hw_ostc_device_dump, /* dump */
hw_ostc_device_foreach, /* foreach */ hw_ostc_device_foreach, /* foreach */
hw_ostc_device_timesync, /* timesync */ hw_ostc_device_timesync, /* timesync */
hw_ostc_device_close /* close */ NULL /* close */
}; };
static dc_status_t static dc_status_t
@ -123,7 +121,7 @@ hw_ostc_send (hw_ostc_device_t *device, unsigned char cmd, unsigned int echo)
dc_status_t dc_status_t
hw_ostc_device_open (dc_device_t **out, dc_context_t *context, const char *name) hw_ostc_device_open (dc_device_t **out, dc_context_t *context, dc_iostream_t *iostream)
{ {
dc_status_t status = DC_STATUS_SUCCESS; dc_status_t status = DC_STATUS_SUCCESS;
hw_ostc_device_t *device = NULL; hw_ostc_device_t *device = NULL;
@ -139,28 +137,21 @@ hw_ostc_device_open (dc_device_t **out, dc_context_t *context, const char *name)
} }
// Set the default values. // Set the default values.
device->iostream = NULL; device->iostream = iostream;
memset (device->fingerprint, 0, sizeof (device->fingerprint)); memset (device->fingerprint, 0, sizeof (device->fingerprint));
// Open the device.
status = dc_serial_open (&device->iostream, context, name);
if (status != DC_STATUS_SUCCESS) {
ERROR (context, "Failed to open the serial port.");
goto error_free;
}
// Set the serial communication protocol (115200 8N1). // Set the serial communication protocol (115200 8N1).
status = dc_iostream_configure (device->iostream, 115200, 8, DC_PARITY_NONE, DC_STOPBITS_ONE, DC_FLOWCONTROL_NONE); status = dc_iostream_configure (device->iostream, 115200, 8, DC_PARITY_NONE, DC_STOPBITS_ONE, DC_FLOWCONTROL_NONE);
if (status != DC_STATUS_SUCCESS) { if (status != DC_STATUS_SUCCESS) {
ERROR (context, "Failed to set the terminal attributes."); ERROR (context, "Failed to set the terminal attributes.");
goto error_close; goto error_free;
} }
// Set the timeout for receiving data. // Set the timeout for receiving data.
status = dc_iostream_set_timeout (device->iostream, 4000); status = dc_iostream_set_timeout (device->iostream, 4000);
if (status != DC_STATUS_SUCCESS) { if (status != DC_STATUS_SUCCESS) {
ERROR (context, "Failed to set the timeout."); ERROR (context, "Failed to set the timeout.");
goto error_close; goto error_free;
} }
// Make sure everything is in a sane state. // Make sure everything is in a sane state.
@ -171,31 +162,12 @@ hw_ostc_device_open (dc_device_t **out, dc_context_t *context, const char *name)
return DC_STATUS_SUCCESS; return DC_STATUS_SUCCESS;
error_close:
dc_iostream_close (device->iostream);
error_free: error_free:
dc_device_deallocate ((dc_device_t *) device); dc_device_deallocate ((dc_device_t *) device);
return status; return status;
} }
static dc_status_t
hw_ostc_device_close (dc_device_t *abstract)
{
dc_status_t status = DC_STATUS_SUCCESS;
hw_ostc_device_t *device = (hw_ostc_device_t*) abstract;
dc_status_t rc = DC_STATUS_SUCCESS;
// Close the device.
rc = dc_iostream_close (device->iostream);
if (rc != DC_STATUS_SUCCESS) {
dc_status_set_error(&status, rc);
}
return status;
}
static dc_status_t static dc_status_t
hw_ostc_device_set_fingerprint (dc_device_t *abstract, const unsigned char data[], unsigned int size) hw_ostc_device_set_fingerprint (dc_device_t *abstract, const unsigned char data[], unsigned int size)
{ {

View File

@ -23,6 +23,7 @@
#define HW_OSTC_H #define HW_OSTC_H
#include <libdivecomputer/context.h> #include <libdivecomputer/context.h>
#include <libdivecomputer/iostream.h>
#include <libdivecomputer/device.h> #include <libdivecomputer/device.h>
#include <libdivecomputer/parser.h> #include <libdivecomputer/parser.h>
#include <libdivecomputer/hw_ostc.h> #include <libdivecomputer/hw_ostc.h>
@ -32,7 +33,7 @@ extern "C" {
#endif /* __cplusplus */ #endif /* __cplusplus */
dc_status_t dc_status_t
hw_ostc_device_open (dc_device_t **device, dc_context_t *context, const char *name); hw_ostc_device_open (dc_device_t **device, dc_context_t *context, dc_iostream_t *iostream);
dc_status_t dc_status_t
hw_ostc_parser_create (dc_parser_t **parser, dc_context_t *context, unsigned int hwos); hw_ostc_parser_create (dc_parser_t **parser, dc_context_t *context, unsigned int hwos);

View File

@ -27,7 +27,6 @@
#include "hw_ostc3.h" #include "hw_ostc3.h"
#include "context-private.h" #include "context-private.h"
#include "device-private.h" #include "device-private.h"
#include "serial.h"
#include "array.h" #include "array.h"
#include "aes.h" #include "aes.h"
#include "platform.h" #include "platform.h"
@ -316,7 +315,7 @@ hw_ostc3_transfer (hw_ostc3_device_t *device,
dc_status_t dc_status_t
hw_ostc3_device_open (dc_device_t **out, dc_context_t *context, const char *name) hw_ostc3_device_open (dc_device_t **out, dc_context_t *context, dc_iostream_t *iostream)
{ {
dc_status_t status = DC_STATUS_SUCCESS; dc_status_t status = DC_STATUS_SUCCESS;
hw_ostc3_device_t *device = NULL; hw_ostc3_device_t *device = NULL;
@ -332,31 +331,24 @@ hw_ostc3_device_open (dc_device_t **out, dc_context_t *context, const char *name
} }
// Set the default values. // Set the default values.
device->iostream = NULL; device->iostream = iostream;
device->hardware = INVALID; device->hardware = INVALID;
device->feature = 0; device->feature = 0;
device->model = 0; device->model = 0;
memset (device->fingerprint, 0, sizeof (device->fingerprint)); memset (device->fingerprint, 0, sizeof (device->fingerprint));
// Open the device.
status = dc_serial_open (&device->iostream, context, name);
if (status != DC_STATUS_SUCCESS) {
ERROR (context, "Failed to open the serial port.");
goto error_free;
}
// Set the serial communication protocol (115200 8N1). // Set the serial communication protocol (115200 8N1).
status = dc_iostream_configure (device->iostream, 115200, 8, DC_PARITY_NONE, DC_STOPBITS_ONE, DC_FLOWCONTROL_NONE); status = dc_iostream_configure (device->iostream, 115200, 8, DC_PARITY_NONE, DC_STOPBITS_ONE, DC_FLOWCONTROL_NONE);
if (status != DC_STATUS_SUCCESS) { if (status != DC_STATUS_SUCCESS) {
ERROR (context, "Failed to set the terminal attributes."); ERROR (context, "Failed to set the terminal attributes.");
goto error_close; goto error_free;
} }
// Set the timeout for receiving data (3000ms). // Set the timeout for receiving data (3000ms).
status = dc_iostream_set_timeout (device->iostream, 3000); status = dc_iostream_set_timeout (device->iostream, 3000);
if (status != DC_STATUS_SUCCESS) { if (status != DC_STATUS_SUCCESS) {
ERROR (context, "Failed to set the timeout."); ERROR (context, "Failed to set the timeout.");
goto error_close; goto error_free;
} }
// Make sure everything is in a sane state. // Make sure everything is in a sane state.
@ -369,8 +361,6 @@ hw_ostc3_device_open (dc_device_t **out, dc_context_t *context, const char *name
return DC_STATUS_SUCCESS; return DC_STATUS_SUCCESS;
error_close:
dc_iostream_close (device->iostream);
error_free: error_free:
dc_device_deallocate ((dc_device_t *) device); dc_device_deallocate ((dc_device_t *) device);
return status; return status;
@ -531,12 +521,6 @@ hw_ostc3_device_close (dc_device_t *abstract)
} }
} }
// Close the device.
rc = dc_iostream_close (device->iostream);
if (rc != DC_STATUS_SUCCESS) {
dc_status_set_error(&status, rc);
}
return status; return status;
} }

View File

@ -23,6 +23,7 @@
#define HW_OSTC3_H #define HW_OSTC3_H
#include <libdivecomputer/context.h> #include <libdivecomputer/context.h>
#include <libdivecomputer/iostream.h>
#include <libdivecomputer/device.h> #include <libdivecomputer/device.h>
#include <libdivecomputer/parser.h> #include <libdivecomputer/parser.h>
#include <libdivecomputer/hw_ostc3.h> #include <libdivecomputer/hw_ostc3.h>
@ -32,7 +33,7 @@ extern "C" {
#endif /* __cplusplus */ #endif /* __cplusplus */
dc_status_t dc_status_t
hw_ostc3_device_open (dc_device_t **device, dc_context_t *context, const char *name); hw_ostc3_device_open (dc_device_t **device, dc_context_t *context, dc_iostream_t *iostream);
dc_status_t dc_status_t
hw_ostc3_parser_create (dc_parser_t **out, dc_context_t *context, unsigned int model); hw_ostc3_parser_create (dc_parser_t **out, dc_context_t *context, unsigned int model);

View File

@ -35,6 +35,7 @@ typedef struct dc_iostream_vtable_t dc_iostream_vtable_t;
struct dc_iostream_t { struct dc_iostream_t {
const dc_iostream_vtable_t *vtable; const dc_iostream_vtable_t *vtable;
dc_context_t *context; dc_context_t *context;
dc_transport_t transport;
}; };
struct dc_iostream_vtable_t { struct dc_iostream_vtable_t {
@ -70,7 +71,7 @@ struct dc_iostream_vtable_t {
}; };
dc_iostream_t * dc_iostream_t *
dc_iostream_allocate (dc_context_t *context, const dc_iostream_vtable_t *vtable); dc_iostream_allocate (dc_context_t *context, const dc_iostream_vtable_t *vtable, dc_transport_t transport);
void void
dc_iostream_deallocate (dc_iostream_t *iostream); dc_iostream_deallocate (dc_iostream_t *iostream);

View File

@ -27,7 +27,7 @@
#include "context-private.h" #include "context-private.h"
dc_iostream_t * dc_iostream_t *
dc_iostream_allocate (dc_context_t *context, const dc_iostream_vtable_t *vtable) dc_iostream_allocate (dc_context_t *context, const dc_iostream_vtable_t *vtable, dc_transport_t transport)
{ {
dc_iostream_t *iostream = NULL; dc_iostream_t *iostream = NULL;
@ -44,6 +44,7 @@ dc_iostream_allocate (dc_context_t *context, const dc_iostream_vtable_t *vtable)
// Initialize the base class. // Initialize the base class.
iostream->vtable = vtable; iostream->vtable = vtable;
iostream->context = context; iostream->context = context;
iostream->transport = transport;
return iostream; return iostream;
} }
@ -63,6 +64,15 @@ dc_iostream_isinstance (dc_iostream_t *iostream, const dc_iostream_vtable_t *vta
return iostream->vtable == vtable; return iostream->vtable == vtable;
} }
dc_transport_t
dc_iostream_get_transport (dc_iostream_t *iostream)
{
if (iostream == NULL)
return DC_TRANSPORT_NONE;
return iostream->transport;
}
dc_status_t dc_status_t
dc_iostream_set_timeout (dc_iostream_t *iostream, int timeout) dc_iostream_set_timeout (dc_iostream_t *iostream, int timeout)
{ {

View File

@ -42,7 +42,7 @@
#endif #endif
#endif #endif
#include "irda.h" #include <libdivecomputer/irda.h>
#include "common-private.h" #include "common-private.h"
#include "context-private.h" #include "context-private.h"
@ -300,7 +300,7 @@ dc_irda_open (dc_iostream_t **out, dc_context_t *context, unsigned int address,
INFO (context, "Open: address=%08x, lsap=%u", address, lsap); INFO (context, "Open: address=%08x, lsap=%u", address, lsap);
// Allocate memory. // Allocate memory.
device = (dc_socket_t *) dc_iostream_allocate (context, &dc_irda_vtable); device = (dc_socket_t *) dc_iostream_allocate (context, &dc_irda_vtable, DC_TRANSPORT_IRDA);
if (device == NULL) { if (device == NULL) {
SYSERROR (context, S_ENOMEM); SYSERROR (context, S_ENOMEM);
return DC_STATUS_NOMEMORY; return DC_STATUS_NOMEMORY;

View File

@ -21,6 +21,7 @@ dc_context_new
dc_context_free dc_context_free
dc_context_set_loglevel dc_context_set_loglevel
dc_context_set_logfunc dc_context_set_logfunc
dc_context_get_transports
dc_iterator_next dc_iterator_next
dc_iterator_free dc_iterator_free
@ -31,8 +32,9 @@ dc_descriptor_get_vendor
dc_descriptor_get_product dc_descriptor_get_product
dc_descriptor_get_type dc_descriptor_get_type
dc_descriptor_get_model dc_descriptor_get_model
dc_descriptor_get_transport dc_descriptor_get_transports
dc_iostream_get_transport
dc_iostream_set_timeout dc_iostream_set_timeout
dc_iostream_set_latency dc_iostream_set_latency
dc_iostream_set_break dc_iostream_set_break
@ -48,6 +50,33 @@ dc_iostream_purge
dc_iostream_sleep dc_iostream_sleep
dc_iostream_close dc_iostream_close
dc_serial_device_get_name
dc_serial_device_free
dc_serial_iterator_new
dc_serial_open
dc_bluetooth_addr2str
dc_bluetooth_str2addr
dc_bluetooth_device_get_address
dc_bluetooth_device_get_name
dc_bluetooth_device_free
dc_bluetooth_iterator_new
dc_bluetooth_open
dc_irda_device_get_address
dc_irda_device_get_name
dc_irda_device_free
dc_irda_iterator_new
dc_irda_open
dc_usbhid_device_get_vid
dc_usbhid_device_get_pid
dc_usbhid_device_free
dc_usbhid_iterator_new
dc_usbhid_open
dc_custom_open
dc_parser_new dc_parser_new
dc_parser_new2 dc_parser_new2
dc_parser_get_type dc_parser_get_type

View File

@ -47,12 +47,12 @@
#define GAUGE 3 #define GAUGE 3
void void
mares_common_device_init (mares_common_device_t *device) mares_common_device_init (mares_common_device_t *device, dc_iostream_t *iostream)
{ {
assert (device != NULL); assert (device != NULL);
// Set the default values. // Set the default values.
device->iostream = NULL; device->iostream = iostream;
device->echo = 0; device->echo = 0;
device->delay = 0; device->delay = 0;
} }

View File

@ -22,8 +22,9 @@
#ifndef MARES_COMMON_H #ifndef MARES_COMMON_H
#define MARES_COMMON_H #define MARES_COMMON_H
#include <libdivecomputer/iostream.h>
#include "device-private.h" #include "device-private.h"
#include "serial.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
@ -47,7 +48,7 @@ typedef struct mares_common_device_t {
} mares_common_device_t; } mares_common_device_t;
void void
mares_common_device_init (mares_common_device_t *device); mares_common_device_init (mares_common_device_t *device, dc_iostream_t *iostream);
dc_status_t dc_status_t
mares_common_device_read (dc_device_t *abstract, unsigned int address, unsigned char data[], unsigned int size); mares_common_device_read (dc_device_t *abstract, unsigned int address, unsigned char data[], unsigned int size);

View File

@ -60,7 +60,6 @@ typedef struct mares_darwin_device_t {
static dc_status_t mares_darwin_device_set_fingerprint (dc_device_t *abstract, const unsigned char data[], unsigned int size); static dc_status_t mares_darwin_device_set_fingerprint (dc_device_t *abstract, const unsigned char data[], unsigned int size);
static dc_status_t mares_darwin_device_dump (dc_device_t *abstract, dc_buffer_t *buffer); static dc_status_t mares_darwin_device_dump (dc_device_t *abstract, dc_buffer_t *buffer);
static dc_status_t mares_darwin_device_foreach (dc_device_t *abstract, dc_dive_callback_t callback, void *userdata); static dc_status_t mares_darwin_device_foreach (dc_device_t *abstract, dc_dive_callback_t callback, void *userdata);
static dc_status_t mares_darwin_device_close (dc_device_t *abstract);
static const dc_device_vtable_t mares_darwin_device_vtable = { static const dc_device_vtable_t mares_darwin_device_vtable = {
sizeof(mares_darwin_device_t), sizeof(mares_darwin_device_t),
@ -71,7 +70,7 @@ static const dc_device_vtable_t mares_darwin_device_vtable = {
mares_darwin_device_dump, /* dump */ mares_darwin_device_dump, /* dump */
mares_darwin_device_foreach, /* foreach */ mares_darwin_device_foreach, /* foreach */
NULL, /* timesync */ NULL, /* timesync */
mares_darwin_device_close /* close */ NULL /* close */
}; };
static const mares_darwin_layout_t mares_darwin_layout = { static const mares_darwin_layout_t mares_darwin_layout = {
@ -98,7 +97,7 @@ static dc_status_t
mares_darwin_extract_dives (dc_device_t *device, const unsigned char data[], unsigned int size, dc_dive_callback_t callback, void *userdata); mares_darwin_extract_dives (dc_device_t *device, const unsigned char data[], unsigned int size, dc_dive_callback_t callback, void *userdata);
dc_status_t dc_status_t
mares_darwin_device_open (dc_device_t **out, dc_context_t *context, const char *name, unsigned int model) mares_darwin_device_open (dc_device_t **out, dc_context_t *context, dc_iostream_t *iostream, unsigned int model)
{ {
dc_status_t status = DC_STATUS_SUCCESS; dc_status_t status = DC_STATUS_SUCCESS;
mares_darwin_device_t *device = NULL; mares_darwin_device_t *device = NULL;
@ -114,7 +113,7 @@ mares_darwin_device_open (dc_device_t **out, dc_context_t *context, const char *
} }
// Initialize the base class. // Initialize the base class.
mares_common_device_init (&device->base); mares_common_device_init (&device->base, iostream);
// Set the default values. // Set the default values.
memset (device->fingerprint, 0, sizeof (device->fingerprint)); memset (device->fingerprint, 0, sizeof (device->fingerprint));
@ -124,39 +123,32 @@ mares_darwin_device_open (dc_device_t **out, dc_context_t *context, const char *
else else
device->layout = &mares_darwin_layout; device->layout = &mares_darwin_layout;
// Open the device.
status = dc_serial_open (&device->base.iostream, context, name);
if (status != DC_STATUS_SUCCESS) {
ERROR (context, "Failed to open the serial port.");
goto error_free;
}
// Set the serial communication protocol (9600 8N1). // Set the serial communication protocol (9600 8N1).
status = dc_iostream_configure (device->base.iostream, 9600, 8, DC_PARITY_NONE, DC_STOPBITS_ONE, DC_FLOWCONTROL_NONE); status = dc_iostream_configure (device->base.iostream, 9600, 8, DC_PARITY_NONE, DC_STOPBITS_ONE, DC_FLOWCONTROL_NONE);
if (status != DC_STATUS_SUCCESS) { if (status != DC_STATUS_SUCCESS) {
ERROR (context, "Failed to set the terminal attributes."); ERROR (context, "Failed to set the terminal attributes.");
goto error_close; goto error_free;
} }
// Set the timeout for receiving data (1000 ms). // Set the timeout for receiving data (1000 ms).
status = dc_iostream_set_timeout (device->base.iostream, 1000); status = dc_iostream_set_timeout (device->base.iostream, 1000);
if (status != DC_STATUS_SUCCESS) { if (status != DC_STATUS_SUCCESS) {
ERROR (context, "Failed to set the timeout."); ERROR (context, "Failed to set the timeout.");
goto error_close; goto error_free;
} }
// Set the DTR line. // Set the DTR line.
status = dc_iostream_set_dtr (device->base.iostream, 1); status = dc_iostream_set_dtr (device->base.iostream, 1);
if (status != DC_STATUS_SUCCESS) { if (status != DC_STATUS_SUCCESS) {
ERROR (context, "Failed to set the DTR line."); ERROR (context, "Failed to set the DTR line.");
goto error_close; goto error_free;
} }
// Set the RTS line. // Set the RTS line.
status = dc_iostream_set_rts (device->base.iostream, 1); status = dc_iostream_set_rts (device->base.iostream, 1);
if (status != DC_STATUS_SUCCESS) { if (status != DC_STATUS_SUCCESS) {
ERROR (context, "Failed to set the RTS line."); ERROR (context, "Failed to set the RTS line.");
goto error_close; goto error_free;
} }
// Make sure everything is in a sane state. // Make sure everything is in a sane state.
@ -171,29 +163,11 @@ mares_darwin_device_open (dc_device_t **out, dc_context_t *context, const char *
return DC_STATUS_SUCCESS; return DC_STATUS_SUCCESS;
error_close:
dc_iostream_close (device->base.iostream);
error_free: error_free:
dc_device_deallocate ((dc_device_t *) device); dc_device_deallocate ((dc_device_t *) device);
return status; return status;
} }
static dc_status_t
mares_darwin_device_close (dc_device_t *abstract)
{
dc_status_t status = DC_STATUS_SUCCESS;
mares_darwin_device_t *device = (mares_darwin_device_t *) abstract;
dc_status_t rc = DC_STATUS_SUCCESS;
// Close the device.
rc = dc_iostream_close (device->base.iostream);
if (rc != DC_STATUS_SUCCESS) {
dc_status_set_error(&status, rc);
}
return status;
}
static dc_status_t static dc_status_t
mares_darwin_device_set_fingerprint (dc_device_t *abstract, const unsigned char data[], unsigned int size) mares_darwin_device_set_fingerprint (dc_device_t *abstract, const unsigned char data[], unsigned int size)

View File

@ -23,6 +23,7 @@
#define MARES_DARWIN_H #define MARES_DARWIN_H
#include <libdivecomputer/context.h> #include <libdivecomputer/context.h>
#include <libdivecomputer/iostream.h>
#include <libdivecomputer/device.h> #include <libdivecomputer/device.h>
#include <libdivecomputer/parser.h> #include <libdivecomputer/parser.h>
@ -31,7 +32,7 @@ extern "C" {
#endif /* __cplusplus */ #endif /* __cplusplus */
dc_status_t dc_status_t
mares_darwin_device_open (dc_device_t **device, dc_context_t *context, const char *name, unsigned int model); mares_darwin_device_open (dc_device_t **device, dc_context_t *context, dc_iostream_t *iostream, unsigned int model);
dc_status_t dc_status_t
mares_darwin_parser_create (dc_parser_t **parser, dc_context_t *context, unsigned int model); mares_darwin_parser_create (dc_parser_t **parser, dc_context_t *context, unsigned int model);

View File

@ -26,7 +26,6 @@
#include "mares_iconhd.h" #include "mares_iconhd.h"
#include "context-private.h" #include "context-private.h"
#include "device-private.h" #include "device-private.h"
#include "serial.h"
#include "array.h" #include "array.h"
#include "rbstream.h" #include "rbstream.h"
@ -78,7 +77,6 @@ static dc_status_t mares_iconhd_device_set_fingerprint (dc_device_t *abstract, c
static dc_status_t mares_iconhd_device_read (dc_device_t *abstract, unsigned int address, unsigned char data[], unsigned int size); static dc_status_t mares_iconhd_device_read (dc_device_t *abstract, unsigned int address, unsigned char data[], unsigned int size);
static dc_status_t mares_iconhd_device_dump (dc_device_t *abstract, dc_buffer_t *buffer); static dc_status_t mares_iconhd_device_dump (dc_device_t *abstract, dc_buffer_t *buffer);
static dc_status_t mares_iconhd_device_foreach (dc_device_t *abstract, dc_dive_callback_t callback, void *userdata); static dc_status_t mares_iconhd_device_foreach (dc_device_t *abstract, dc_dive_callback_t callback, void *userdata);
static dc_status_t mares_iconhd_device_close (dc_device_t *abstract);
static const dc_device_vtable_t mares_iconhd_device_vtable = { static const dc_device_vtable_t mares_iconhd_device_vtable = {
sizeof(mares_iconhd_device_t), sizeof(mares_iconhd_device_t),
@ -89,7 +87,7 @@ static const dc_device_vtable_t mares_iconhd_device_vtable = {
mares_iconhd_device_dump, /* dump */ mares_iconhd_device_dump, /* dump */
mares_iconhd_device_foreach, /* foreach */ mares_iconhd_device_foreach, /* foreach */
NULL, /* timesync */ NULL, /* timesync */
mares_iconhd_device_close /* close */ NULL /* close */
}; };
static const mares_iconhd_layout_t mares_iconhd_layout = { static const mares_iconhd_layout_t mares_iconhd_layout = {
@ -214,7 +212,7 @@ mares_iconhd_transfer (mares_iconhd_device_t *device,
dc_status_t dc_status_t
mares_iconhd_device_open (dc_device_t **out, dc_context_t *context, const char *name) mares_iconhd_device_open (dc_device_t **out, dc_context_t *context, dc_iostream_t *iostream)
{ {
dc_status_t status = DC_STATUS_SUCCESS; dc_status_t status = DC_STATUS_SUCCESS;
mares_iconhd_device_t *device = NULL; mares_iconhd_device_t *device = NULL;
@ -230,46 +228,39 @@ mares_iconhd_device_open (dc_device_t **out, dc_context_t *context, const char *
} }
// Set the default values. // Set the default values.
device->iostream = NULL; device->iostream = iostream;
device->layout = NULL; device->layout = NULL;
memset (device->fingerprint, 0, sizeof (device->fingerprint)); memset (device->fingerprint, 0, sizeof (device->fingerprint));
memset (device->version, 0, sizeof (device->version)); memset (device->version, 0, sizeof (device->version));
device->model = 0; device->model = 0;
device->packetsize = 0; device->packetsize = 0;
// Open the device.
status = dc_serial_open (&device->iostream, context, name);
if (status != DC_STATUS_SUCCESS) {
ERROR (context, "Failed to open the serial port.");
goto error_free;
}
// Set the serial communication protocol (115200 8E1). // Set the serial communication protocol (115200 8E1).
status = dc_iostream_configure (device->iostream, 115200, 8, DC_PARITY_EVEN, DC_STOPBITS_ONE, DC_FLOWCONTROL_NONE); status = dc_iostream_configure (device->iostream, 115200, 8, DC_PARITY_EVEN, DC_STOPBITS_ONE, DC_FLOWCONTROL_NONE);
if (status != DC_STATUS_SUCCESS) { if (status != DC_STATUS_SUCCESS) {
ERROR (context, "Failed to set the terminal attributes."); ERROR (context, "Failed to set the terminal attributes.");
goto error_close; goto error_free;
} }
// Set the timeout for receiving data (1000 ms). // Set the timeout for receiving data (1000 ms).
status = dc_iostream_set_timeout (device->iostream, 1000); status = dc_iostream_set_timeout (device->iostream, 1000);
if (status != DC_STATUS_SUCCESS) { if (status != DC_STATUS_SUCCESS) {
ERROR (context, "Failed to set the timeout."); ERROR (context, "Failed to set the timeout.");
goto error_close; goto error_free;
} }
// Clear the DTR line. // Clear the DTR line.
status = dc_iostream_set_dtr (device->iostream, 0); status = dc_iostream_set_dtr (device->iostream, 0);
if (status != DC_STATUS_SUCCESS) { if (status != DC_STATUS_SUCCESS) {
ERROR (context, "Failed to clear the DTR line."); ERROR (context, "Failed to clear the DTR line.");
goto error_close; goto error_free;
} }
// Clear the RTS line. // Clear the RTS line.
status = dc_iostream_set_rts (device->iostream, 0); status = dc_iostream_set_rts (device->iostream, 0);
if (status != DC_STATUS_SUCCESS) { if (status != DC_STATUS_SUCCESS) {
ERROR (context, "Failed to clear the RTS line."); ERROR (context, "Failed to clear the RTS line.");
goto error_close; goto error_free;
} }
// Make sure everything is in a sane state. // Make sure everything is in a sane state.
@ -280,7 +271,7 @@ mares_iconhd_device_open (dc_device_t **out, dc_context_t *context, const char *
status = mares_iconhd_transfer (device, command, sizeof (command), status = mares_iconhd_transfer (device, command, sizeof (command),
device->version, sizeof (device->version)); device->version, sizeof (device->version));
if (status != DC_STATUS_SUCCESS) { if (status != DC_STATUS_SUCCESS) {
goto error_close; goto error_free;
} }
// Autodetect the model using the version packet. // Autodetect the model using the version packet.
@ -320,31 +311,12 @@ mares_iconhd_device_open (dc_device_t **out, dc_context_t *context, const char *
return DC_STATUS_SUCCESS; return DC_STATUS_SUCCESS;
error_close:
dc_iostream_close (device->iostream);
error_free: error_free:
dc_device_deallocate ((dc_device_t *) device); dc_device_deallocate ((dc_device_t *) device);
return status; return status;
} }
static dc_status_t
mares_iconhd_device_close (dc_device_t *abstract)
{
dc_status_t status = DC_STATUS_SUCCESS;
mares_iconhd_device_t *device = (mares_iconhd_device_t*) abstract;
dc_status_t rc = DC_STATUS_SUCCESS;
// Close the device.
rc = dc_iostream_close (device->iostream);
if (rc != DC_STATUS_SUCCESS) {
dc_status_set_error(&status, rc);
}
return status;
}
static dc_status_t static dc_status_t
mares_iconhd_device_set_fingerprint (dc_device_t *abstract, const unsigned char data[], unsigned int size) mares_iconhd_device_set_fingerprint (dc_device_t *abstract, const unsigned char data[], unsigned int size)
{ {

View File

@ -23,6 +23,7 @@
#define MARES_ICONHD_H #define MARES_ICONHD_H
#include <libdivecomputer/context.h> #include <libdivecomputer/context.h>
#include <libdivecomputer/iostream.h>
#include <libdivecomputer/device.h> #include <libdivecomputer/device.h>
#include <libdivecomputer/parser.h> #include <libdivecomputer/parser.h>
@ -31,7 +32,7 @@ extern "C" {
#endif /* __cplusplus */ #endif /* __cplusplus */
dc_status_t dc_status_t
mares_iconhd_device_open (dc_device_t **device, dc_context_t *context, const char *name); mares_iconhd_device_open (dc_device_t **device, dc_context_t *context, dc_iostream_t *iostream);
dc_status_t dc_status_t
mares_iconhd_parser_create (dc_parser_t **parser, dc_context_t *context, unsigned int model); mares_iconhd_parser_create (dc_parser_t **parser, dc_context_t *context, unsigned int model);

View File

@ -26,7 +26,6 @@
#include "mares_common.h" #include "mares_common.h"
#include "context-private.h" #include "context-private.h"
#include "device-private.h" #include "device-private.h"
#include "serial.h"
#include "checksum.h" #include "checksum.h"
#include "array.h" #include "array.h"
@ -52,7 +51,6 @@ typedef struct mares_nemo_device_t {
static dc_status_t mares_nemo_device_set_fingerprint (dc_device_t *abstract, const unsigned char data[], unsigned int size); static dc_status_t mares_nemo_device_set_fingerprint (dc_device_t *abstract, const unsigned char data[], unsigned int size);
static dc_status_t mares_nemo_device_dump (dc_device_t *abstract, dc_buffer_t *buffer); static dc_status_t mares_nemo_device_dump (dc_device_t *abstract, dc_buffer_t *buffer);
static dc_status_t mares_nemo_device_foreach (dc_device_t *abstract, dc_dive_callback_t callback, void *userdata); static dc_status_t mares_nemo_device_foreach (dc_device_t *abstract, dc_dive_callback_t callback, void *userdata);
static dc_status_t mares_nemo_device_close (dc_device_t *abstract);
static const dc_device_vtable_t mares_nemo_device_vtable = { static const dc_device_vtable_t mares_nemo_device_vtable = {
sizeof(mares_nemo_device_t), sizeof(mares_nemo_device_t),
@ -63,7 +61,7 @@ static const dc_device_vtable_t mares_nemo_device_vtable = {
mares_nemo_device_dump, /* dump */ mares_nemo_device_dump, /* dump */
mares_nemo_device_foreach, /* foreach */ mares_nemo_device_foreach, /* foreach */
NULL, /* timesync */ NULL, /* timesync */
mares_nemo_device_close /* close */ NULL /* close */
}; };
static const mares_common_layout_t mares_nemo_layout = { static const mares_common_layout_t mares_nemo_layout = {
@ -84,7 +82,7 @@ static const mares_common_layout_t mares_nemo_apneist_layout = {
dc_status_t dc_status_t
mares_nemo_device_open (dc_device_t **out, dc_context_t *context, const char *name) mares_nemo_device_open (dc_device_t **out, dc_context_t *context, dc_iostream_t *iostream)
{ {
dc_status_t status = DC_STATUS_SUCCESS; dc_status_t status = DC_STATUS_SUCCESS;
mares_nemo_device_t *device = NULL; mares_nemo_device_t *device = NULL;
@ -100,42 +98,35 @@ mares_nemo_device_open (dc_device_t **out, dc_context_t *context, const char *na
} }
// Set the default values. // Set the default values.
device->iostream = NULL; device->iostream = iostream;
memset (device->fingerprint, 0, sizeof (device->fingerprint)); memset (device->fingerprint, 0, sizeof (device->fingerprint));
// Open the device.
status = dc_serial_open (&device->iostream, context, name);
if (status != DC_STATUS_SUCCESS) {
ERROR (context, "Failed to open the serial port.");
goto error_free;
}
// Set the serial communication protocol (9600 8N1). // Set the serial communication protocol (9600 8N1).
status = dc_iostream_configure (device->iostream, 9600, 8, DC_PARITY_NONE, DC_STOPBITS_ONE, DC_FLOWCONTROL_NONE); status = dc_iostream_configure (device->iostream, 9600, 8, DC_PARITY_NONE, DC_STOPBITS_ONE, DC_FLOWCONTROL_NONE);
if (status != DC_STATUS_SUCCESS) { if (status != DC_STATUS_SUCCESS) {
ERROR (context, "Failed to set the terminal attributes."); ERROR (context, "Failed to set the terminal attributes.");
goto error_close; goto error_free;
} }
// Set the timeout for receiving data (1000 ms). // Set the timeout for receiving data (1000 ms).
status = dc_iostream_set_timeout (device->iostream, 1000); status = dc_iostream_set_timeout (device->iostream, 1000);
if (status != DC_STATUS_SUCCESS) { if (status != DC_STATUS_SUCCESS) {
ERROR (context, "Failed to set the timeout."); ERROR (context, "Failed to set the timeout.");
goto error_close; goto error_free;
} }
// Set the DTR line. // Set the DTR line.
status = dc_iostream_set_dtr (device->iostream, 1); status = dc_iostream_set_dtr (device->iostream, 1);
if (status != DC_STATUS_SUCCESS) { if (status != DC_STATUS_SUCCESS) {
ERROR (context, "Failed to set the DTR line."); ERROR (context, "Failed to set the DTR line.");
goto error_close; goto error_free;
} }
// Set the RTS line. // Set the RTS line.
status = dc_iostream_set_rts (device->iostream, 1); status = dc_iostream_set_rts (device->iostream, 1);
if (status != DC_STATUS_SUCCESS) { if (status != DC_STATUS_SUCCESS) {
ERROR (context, "Failed to set the RTS line."); ERROR (context, "Failed to set the RTS line.");
goto error_close; goto error_free;
} }
// Make sure everything is in a sane state. // Make sure everything is in a sane state.
@ -145,31 +136,12 @@ mares_nemo_device_open (dc_device_t **out, dc_context_t *context, const char *na
return DC_STATUS_SUCCESS; return DC_STATUS_SUCCESS;
error_close:
dc_iostream_close (device->iostream);
error_free: error_free:
dc_device_deallocate ((dc_device_t *) device); dc_device_deallocate ((dc_device_t *) device);
return status; return status;
} }
static dc_status_t
mares_nemo_device_close (dc_device_t *abstract)
{
dc_status_t status = DC_STATUS_SUCCESS;
mares_nemo_device_t *device = (mares_nemo_device_t*) abstract;
dc_status_t rc = DC_STATUS_SUCCESS;
// Close the device.
rc = dc_iostream_close (device->iostream);
if (rc != DC_STATUS_SUCCESS) {
dc_status_set_error(&status, rc);
}
return status;
}
static dc_status_t static dc_status_t
mares_nemo_device_set_fingerprint (dc_device_t *abstract, const unsigned char data[], unsigned int size) mares_nemo_device_set_fingerprint (dc_device_t *abstract, const unsigned char data[], unsigned int size)
{ {

View File

@ -23,6 +23,7 @@
#define MARES_NEMO_H #define MARES_NEMO_H
#include <libdivecomputer/context.h> #include <libdivecomputer/context.h>
#include <libdivecomputer/iostream.h>
#include <libdivecomputer/device.h> #include <libdivecomputer/device.h>
#include <libdivecomputer/parser.h> #include <libdivecomputer/parser.h>
@ -31,7 +32,7 @@ extern "C" {
#endif /* __cplusplus */ #endif /* __cplusplus */
dc_status_t dc_status_t
mares_nemo_device_open (dc_device_t **device, dc_context_t *context, const char *name); mares_nemo_device_open (dc_device_t **device, dc_context_t *context, dc_iostream_t *iostream);
dc_status_t dc_status_t
mares_nemo_parser_create (dc_parser_t **parser, dc_context_t *context, unsigned int model); mares_nemo_parser_create (dc_parser_t **parser, dc_context_t *context, unsigned int model);

View File

@ -27,7 +27,6 @@
#include "mares_common.h" #include "mares_common.h"
#include "context-private.h" #include "context-private.h"
#include "device-private.h" #include "device-private.h"
#include "serial.h"
#include "checksum.h" #include "checksum.h"
#include "array.h" #include "array.h"
@ -47,7 +46,6 @@ typedef struct mares_puck_device_t {
static dc_status_t mares_puck_device_set_fingerprint (dc_device_t *abstract, const unsigned char data[], unsigned int size); static dc_status_t mares_puck_device_set_fingerprint (dc_device_t *abstract, const unsigned char data[], unsigned int size);
static dc_status_t mares_puck_device_dump (dc_device_t *abstract, dc_buffer_t *buffer); static dc_status_t mares_puck_device_dump (dc_device_t *abstract, dc_buffer_t *buffer);
static dc_status_t mares_puck_device_foreach (dc_device_t *abstract, dc_dive_callback_t callback, void *userdata); static dc_status_t mares_puck_device_foreach (dc_device_t *abstract, dc_dive_callback_t callback, void *userdata);
static dc_status_t mares_puck_device_close (dc_device_t *abstract);
static const dc_device_vtable_t mares_puck_device_vtable = { static const dc_device_vtable_t mares_puck_device_vtable = {
sizeof(mares_puck_device_t), sizeof(mares_puck_device_t),
@ -58,7 +56,7 @@ static const dc_device_vtable_t mares_puck_device_vtable = {
mares_puck_device_dump, /* dump */ mares_puck_device_dump, /* dump */
mares_puck_device_foreach, /* foreach */ mares_puck_device_foreach, /* foreach */
NULL, /* timesync */ NULL, /* timesync */
mares_puck_device_close /* close */ NULL /* close */
}; };
static const mares_common_layout_t mares_puck_layout = { static const mares_common_layout_t mares_puck_layout = {
@ -87,7 +85,7 @@ static const mares_common_layout_t mares_nemowide_layout = {
dc_status_t dc_status_t
mares_puck_device_open (dc_device_t **out, dc_context_t *context, const char *name) mares_puck_device_open (dc_device_t **out, dc_context_t *context, dc_iostream_t *iostream)
{ {
dc_status_t status = DC_STATUS_SUCCESS; dc_status_t status = DC_STATUS_SUCCESS;
mares_puck_device_t *device = NULL; mares_puck_device_t *device = NULL;
@ -103,45 +101,38 @@ mares_puck_device_open (dc_device_t **out, dc_context_t *context, const char *na
} }
// Initialize the base class. // Initialize the base class.
mares_common_device_init (&device->base); mares_common_device_init (&device->base, iostream);
// Set the default values. // Set the default values.
device->layout = NULL; device->layout = NULL;
memset (device->fingerprint, 0, sizeof (device->fingerprint)); memset (device->fingerprint, 0, sizeof (device->fingerprint));
// Open the device.
status = dc_serial_open (&device->base.iostream, context, name);
if (status != DC_STATUS_SUCCESS) {
ERROR (context, "Failed to open the serial port.");
goto error_free;
}
// Set the serial communication protocol (38400 8N1). // Set the serial communication protocol (38400 8N1).
status = dc_iostream_configure (device->base.iostream, 38400, 8, DC_PARITY_NONE, DC_STOPBITS_ONE, DC_FLOWCONTROL_NONE); status = dc_iostream_configure (device->base.iostream, 38400, 8, DC_PARITY_NONE, DC_STOPBITS_ONE, DC_FLOWCONTROL_NONE);
if (status != DC_STATUS_SUCCESS) { if (status != DC_STATUS_SUCCESS) {
ERROR (context, "Failed to set the terminal attributes."); ERROR (context, "Failed to set the terminal attributes.");
goto error_close; goto error_free;
} }
// Set the timeout for receiving data (1000 ms). // Set the timeout for receiving data (1000 ms).
status = dc_iostream_set_timeout (device->base.iostream, 1000); status = dc_iostream_set_timeout (device->base.iostream, 1000);
if (status != DC_STATUS_SUCCESS) { if (status != DC_STATUS_SUCCESS) {
ERROR (context, "Failed to set the timeout."); ERROR (context, "Failed to set the timeout.");
goto error_close; goto error_free;
} }
// Clear the DTR line. // Clear the DTR line.
status = dc_iostream_set_dtr (device->base.iostream, 0); status = dc_iostream_set_dtr (device->base.iostream, 0);
if (status != DC_STATUS_SUCCESS) { if (status != DC_STATUS_SUCCESS) {
ERROR (context, "Failed to clear the DTR line."); ERROR (context, "Failed to clear the DTR line.");
goto error_close; goto error_free;
} }
// Clear the RTS line. // Clear the RTS line.
status = dc_iostream_set_rts (device->base.iostream, 0); status = dc_iostream_set_rts (device->base.iostream, 0);
if (status != DC_STATUS_SUCCESS) { if (status != DC_STATUS_SUCCESS) {
ERROR (context, "Failed to clear the RTS line."); ERROR (context, "Failed to clear the RTS line.");
goto error_close; goto error_free;
} }
// Make sure everything is in a sane state. // Make sure everything is in a sane state.
@ -151,7 +142,7 @@ mares_puck_device_open (dc_device_t **out, dc_context_t *context, const char *na
unsigned char header[PACKETSIZE] = {0}; unsigned char header[PACKETSIZE] = {0};
status = mares_common_device_read ((dc_device_t *) device, 0, header, sizeof (header)); status = mares_common_device_read ((dc_device_t *) device, 0, header, sizeof (header));
if (status != DC_STATUS_SUCCESS) { if (status != DC_STATUS_SUCCESS) {
goto error_close; goto error_free;
} }
// Override the base class values. // Override the base class values.
@ -175,31 +166,12 @@ mares_puck_device_open (dc_device_t **out, dc_context_t *context, const char *na
return DC_STATUS_SUCCESS; return DC_STATUS_SUCCESS;
error_close:
dc_iostream_close (device->base.iostream);
error_free: error_free:
dc_device_deallocate ((dc_device_t *) device); dc_device_deallocate ((dc_device_t *) device);
return status; return status;
} }
static dc_status_t
mares_puck_device_close (dc_device_t *abstract)
{
dc_status_t status = DC_STATUS_SUCCESS;
mares_puck_device_t *device = (mares_puck_device_t*) abstract;
dc_status_t rc = DC_STATUS_SUCCESS;
// Close the device.
rc = dc_iostream_close (device->base.iostream);
if (rc != DC_STATUS_SUCCESS) {
dc_status_set_error(&status, rc);
}
return status;
}
static dc_status_t static dc_status_t
mares_puck_device_set_fingerprint (dc_device_t *abstract, const unsigned char data[], unsigned int size) mares_puck_device_set_fingerprint (dc_device_t *abstract, const unsigned char data[], unsigned int size)
{ {

View File

@ -23,6 +23,7 @@
#define MARES_PUCK_H #define MARES_PUCK_H
#include <libdivecomputer/context.h> #include <libdivecomputer/context.h>
#include <libdivecomputer/iostream.h>
#include <libdivecomputer/device.h> #include <libdivecomputer/device.h>
#include <libdivecomputer/parser.h> #include <libdivecomputer/parser.h>
@ -31,7 +32,7 @@ extern "C" {
#endif /* __cplusplus */ #endif /* __cplusplus */
dc_status_t dc_status_t
mares_puck_device_open (dc_device_t **device, dc_context_t *context, const char *name); mares_puck_device_open (dc_device_t **device, dc_context_t *context, dc_iostream_t *iostream);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -26,7 +26,6 @@
#include "oceanic_common.h" #include "oceanic_common.h"
#include "context-private.h" #include "context-private.h"
#include "device-private.h" #include "device-private.h"
#include "serial.h"
#include "array.h" #include "array.h"
#include "ringbuffer.h" #include "ringbuffer.h"
#include "checksum.h" #include "checksum.h"
@ -574,7 +573,7 @@ oceanic_atom2_quit (oceanic_atom2_device_t *device)
dc_status_t dc_status_t
oceanic_atom2_device_open (dc_device_t **out, dc_context_t *context, const char *name, unsigned int model) oceanic_atom2_device_open (dc_device_t **out, dc_context_t *context, dc_iostream_t *iostream, unsigned int model)
{ {
dc_status_t status = DC_STATUS_SUCCESS; dc_status_t status = DC_STATUS_SUCCESS;
oceanic_atom2_device_t *device = NULL; oceanic_atom2_device_t *device = NULL;
@ -593,19 +592,12 @@ oceanic_atom2_device_open (dc_device_t **out, dc_context_t *context, const char
oceanic_common_device_init (&device->base); oceanic_common_device_init (&device->base);
// Set the default values. // Set the default values.
device->iostream = NULL; device->iostream = iostream;
device->delay = 0; device->delay = 0;
device->bigpage = 1; // no big pages device->bigpage = 1; // no big pages
device->cached = INVALID; device->cached = INVALID;
memset(device->cache, 0, sizeof(device->cache)); memset(device->cache, 0, sizeof(device->cache));
// Open the device.
status = dc_serial_open (&device->iostream, context, name);
if (status != DC_STATUS_SUCCESS) {
ERROR (context, "Failed to open the serial port.");
goto error_free;
}
// Get the correct baudrate. // Get the correct baudrate.
unsigned int baudrate = 38400; unsigned int baudrate = 38400;
if (model == VTX || model == I750TC) { if (model == VTX || model == I750TC) {
@ -616,14 +608,14 @@ oceanic_atom2_device_open (dc_device_t **out, dc_context_t *context, const char
status = dc_iostream_configure (device->iostream, baudrate, 8, DC_PARITY_NONE, DC_STOPBITS_ONE, DC_FLOWCONTROL_NONE); status = dc_iostream_configure (device->iostream, baudrate, 8, DC_PARITY_NONE, DC_STOPBITS_ONE, DC_FLOWCONTROL_NONE);
if (status != DC_STATUS_SUCCESS) { if (status != DC_STATUS_SUCCESS) {
ERROR (context, "Failed to set the terminal attributes."); ERROR (context, "Failed to set the terminal attributes.");
goto error_close; goto error_free;
} }
// Set the timeout for receiving data (1000 ms). // Set the timeout for receiving data (1000 ms).
status = dc_iostream_set_timeout (device->iostream, 1000); status = dc_iostream_set_timeout (device->iostream, 1000);
if (status != DC_STATUS_SUCCESS) { if (status != DC_STATUS_SUCCESS) {
ERROR (context, "Failed to set the timeout."); ERROR (context, "Failed to set the timeout.");
goto error_close; goto error_free;
} }
// Give the interface 100 ms to settle and draw power up. // Give the interface 100 ms to settle and draw power up.
@ -649,7 +641,7 @@ oceanic_atom2_device_open (dc_device_t **out, dc_context_t *context, const char
// by connecting the device), or already in download mode. // by connecting the device), or already in download mode.
status = oceanic_atom2_device_version ((dc_device_t *) device, device->base.version, sizeof (device->base.version)); status = oceanic_atom2_device_version ((dc_device_t *) device, device->base.version, sizeof (device->base.version));
if (status != DC_STATUS_SUCCESS) { if (status != DC_STATUS_SUCCESS) {
goto error_close; goto error_free;
} }
// Override the base class values. // Override the base class values.
@ -719,8 +711,6 @@ oceanic_atom2_device_open (dc_device_t **out, dc_context_t *context, const char
return DC_STATUS_SUCCESS; return DC_STATUS_SUCCESS;
error_close:
dc_iostream_close (device->iostream);
error_free: error_free:
dc_device_deallocate ((dc_device_t *) device); dc_device_deallocate ((dc_device_t *) device);
return status; return status;
@ -740,12 +730,6 @@ oceanic_atom2_device_close (dc_device_t *abstract)
dc_status_set_error(&status, rc); dc_status_set_error(&status, rc);
} }
// Close the device.
rc = dc_iostream_close (device->iostream);
if (rc != DC_STATUS_SUCCESS) {
dc_status_set_error(&status, rc);
}
return status; return status;
} }

View File

@ -23,6 +23,7 @@
#define OCEANIC_ATOM2_H #define OCEANIC_ATOM2_H
#include <libdivecomputer/context.h> #include <libdivecomputer/context.h>
#include <libdivecomputer/iostream.h>
#include <libdivecomputer/device.h> #include <libdivecomputer/device.h>
#include <libdivecomputer/parser.h> #include <libdivecomputer/parser.h>
@ -33,7 +34,7 @@ extern "C" {
#endif /* __cplusplus */ #endif /* __cplusplus */
dc_status_t dc_status_t
oceanic_atom2_device_open (dc_device_t **device, dc_context_t *context, const char *name, unsigned int model); oceanic_atom2_device_open (dc_device_t **device, dc_context_t *context, dc_iostream_t *iostream, unsigned int model);
dc_status_t dc_status_t
oceanic_atom2_parser_create (dc_parser_t **parser, dc_context_t *context, unsigned int model); oceanic_atom2_parser_create (dc_parser_t **parser, dc_context_t *context, unsigned int model);

View File

@ -26,7 +26,6 @@
#include "oceanic_common.h" #include "oceanic_common.h"
#include "context-private.h" #include "context-private.h"
#include "device-private.h" #include "device-private.h"
#include "serial.h"
#include "ringbuffer.h" #include "ringbuffer.h"
#include "checksum.h" #include "checksum.h"
@ -226,7 +225,7 @@ oceanic_veo250_quit (oceanic_veo250_device_t *device)
dc_status_t dc_status_t
oceanic_veo250_device_open (dc_device_t **out, dc_context_t *context, const char *name) oceanic_veo250_device_open (dc_device_t **out, dc_context_t *context, dc_iostream_t *iostream)
{ {
dc_status_t status = DC_STATUS_SUCCESS; dc_status_t status = DC_STATUS_SUCCESS;
oceanic_veo250_device_t *device = NULL; oceanic_veo250_device_t *device = NULL;
@ -248,42 +247,35 @@ oceanic_veo250_device_open (dc_device_t **out, dc_context_t *context, const char
device->base.multipage = MULTIPAGE; device->base.multipage = MULTIPAGE;
// Set the default values. // Set the default values.
device->iostream = NULL; device->iostream = iostream;
device->last = 0; device->last = 0;
// Open the device.
status = dc_serial_open (&device->iostream, context, name);
if (status != DC_STATUS_SUCCESS) {
ERROR (context, "Failed to open the serial port.");
goto error_free;
}
// Set the serial communication protocol (9600 8N1). // Set the serial communication protocol (9600 8N1).
status = dc_iostream_configure (device->iostream, 9600, 8, DC_PARITY_NONE, DC_STOPBITS_ONE, DC_FLOWCONTROL_NONE); status = dc_iostream_configure (device->iostream, 9600, 8, DC_PARITY_NONE, DC_STOPBITS_ONE, DC_FLOWCONTROL_NONE);
if (status != DC_STATUS_SUCCESS) { if (status != DC_STATUS_SUCCESS) {
ERROR (context, "Failed to set the terminal attributes."); ERROR (context, "Failed to set the terminal attributes.");
goto error_close; goto error_free;
} }
// Set the timeout for receiving data (3000 ms). // Set the timeout for receiving data (3000 ms).
status = dc_iostream_set_timeout (device->iostream, 3000); status = dc_iostream_set_timeout (device->iostream, 3000);
if (status != DC_STATUS_SUCCESS) { if (status != DC_STATUS_SUCCESS) {
ERROR (context, "Failed to set the timeout."); ERROR (context, "Failed to set the timeout.");
goto error_close; goto error_free;
} }
// Set the DTR line. // Set the DTR line.
status = dc_iostream_set_dtr (device->iostream, 1); status = dc_iostream_set_dtr (device->iostream, 1);
if (status != DC_STATUS_SUCCESS) { if (status != DC_STATUS_SUCCESS) {
ERROR (context, "Failed to set the DTR line."); ERROR (context, "Failed to set the DTR line.");
goto error_close; goto error_free;
} }
// Set the RTS line. // Set the RTS line.
status = dc_iostream_set_rts (device->iostream, 1); status = dc_iostream_set_rts (device->iostream, 1);
if (status != DC_STATUS_SUCCESS) { if (status != DC_STATUS_SUCCESS) {
ERROR (context, "Failed to set the RTS line."); ERROR (context, "Failed to set the RTS line.");
goto error_close; goto error_free;
} }
// Give the interface 100 ms to settle and draw power up. // Give the interface 100 ms to settle and draw power up.
@ -295,7 +287,7 @@ oceanic_veo250_device_open (dc_device_t **out, dc_context_t *context, const char
// Initialize the data cable (PPS mode). // Initialize the data cable (PPS mode).
status = oceanic_veo250_init (device); status = oceanic_veo250_init (device);
if (status != DC_STATUS_SUCCESS) { if (status != DC_STATUS_SUCCESS) {
goto error_close; goto error_free;
} }
// Delay the sending of the version command. // Delay the sending of the version command.
@ -306,7 +298,7 @@ oceanic_veo250_device_open (dc_device_t **out, dc_context_t *context, const char
// the user), or already in download mode. // the user), or already in download mode.
status = oceanic_veo250_device_version ((dc_device_t *) device, device->base.version, sizeof (device->base.version)); status = oceanic_veo250_device_version ((dc_device_t *) device, device->base.version, sizeof (device->base.version));
if (status != DC_STATUS_SUCCESS) { if (status != DC_STATUS_SUCCESS) {
goto error_close; goto error_free;
} }
// Override the base class values. // Override the base class values.
@ -321,8 +313,6 @@ oceanic_veo250_device_open (dc_device_t **out, dc_context_t *context, const char
return DC_STATUS_SUCCESS; return DC_STATUS_SUCCESS;
error_close:
dc_iostream_close (device->iostream);
error_free: error_free:
dc_device_deallocate ((dc_device_t *) device); dc_device_deallocate ((dc_device_t *) device);
return status; return status;
@ -342,12 +332,6 @@ oceanic_veo250_device_close (dc_device_t *abstract)
dc_status_set_error(&status, rc); dc_status_set_error(&status, rc);
} }
// Close the device.
rc = dc_iostream_close (device->iostream);
if (rc != DC_STATUS_SUCCESS) {
dc_status_set_error(&status, rc);
}
return status; return status;
} }

View File

@ -23,6 +23,7 @@
#define OCEANIC_VEO250_H #define OCEANIC_VEO250_H
#include <libdivecomputer/context.h> #include <libdivecomputer/context.h>
#include <libdivecomputer/iostream.h>
#include <libdivecomputer/device.h> #include <libdivecomputer/device.h>
#include <libdivecomputer/parser.h> #include <libdivecomputer/parser.h>
@ -33,7 +34,7 @@ extern "C" {
#endif /* __cplusplus */ #endif /* __cplusplus */
dc_status_t dc_status_t
oceanic_veo250_device_open (dc_device_t **device, dc_context_t *context, const char *name); oceanic_veo250_device_open (dc_device_t **device, dc_context_t *context, dc_iostream_t *iostream);
dc_status_t dc_status_t
oceanic_veo250_parser_create (dc_parser_t **parser, dc_context_t *context, unsigned int model); oceanic_veo250_parser_create (dc_parser_t **parser, dc_context_t *context, unsigned int model);

View File

@ -27,7 +27,6 @@
#include "oceanic_common.h" #include "oceanic_common.h"
#include "context-private.h" #include "context-private.h"
#include "device-private.h" #include "device-private.h"
#include "serial.h"
#include "ringbuffer.h" #include "ringbuffer.h"
#include "checksum.h" #include "checksum.h"
#include "array.h" #include "array.h"
@ -389,7 +388,7 @@ oceanic_vtpro_device_logbook (dc_device_t *abstract, dc_event_progress_t *progre
} }
dc_status_t dc_status_t
oceanic_vtpro_device_open (dc_device_t **out, dc_context_t *context, const char *name, unsigned int model) oceanic_vtpro_device_open (dc_device_t **out, dc_context_t *context, dc_iostream_t *iostream, unsigned int model)
{ {
dc_status_t status = DC_STATUS_SUCCESS; dc_status_t status = DC_STATUS_SUCCESS;
oceanic_vtpro_device_t *device = NULL; oceanic_vtpro_device_t *device = NULL;
@ -411,7 +410,7 @@ oceanic_vtpro_device_open (dc_device_t **out, dc_context_t *context, const char
device->base.multipage = MULTIPAGE; device->base.multipage = MULTIPAGE;
// Set the default values. // Set the default values.
device->iostream = NULL; device->iostream = iostream;
device->model = model; device->model = model;
if (model == AERIS500AI) { if (model == AERIS500AI) {
device->protocol = INTR; device->protocol = INTR;
@ -419,39 +418,32 @@ oceanic_vtpro_device_open (dc_device_t **out, dc_context_t *context, const char
device->protocol = MOD; device->protocol = MOD;
} }
// Open the device.
status = dc_serial_open (&device->iostream, context, name);
if (status != DC_STATUS_SUCCESS) {
ERROR (context, "Failed to open the serial port.");
goto error_free;
}
// Set the serial communication protocol (9600 8N1). // Set the serial communication protocol (9600 8N1).
status = dc_iostream_configure (device->iostream, 9600, 8, DC_PARITY_NONE, DC_STOPBITS_ONE, DC_FLOWCONTROL_NONE); status = dc_iostream_configure (device->iostream, 9600, 8, DC_PARITY_NONE, DC_STOPBITS_ONE, DC_FLOWCONTROL_NONE);
if (status != DC_STATUS_SUCCESS) { if (status != DC_STATUS_SUCCESS) {
ERROR (context, "Failed to set the terminal attributes."); ERROR (context, "Failed to set the terminal attributes.");
goto error_close; goto error_free;
} }
// Set the timeout for receiving data (3000 ms). // Set the timeout for receiving data (3000 ms).
status = dc_iostream_set_timeout (device->iostream, 3000); status = dc_iostream_set_timeout (device->iostream, 3000);
if (status != DC_STATUS_SUCCESS) { if (status != DC_STATUS_SUCCESS) {
ERROR (context, "Failed to set the timeout."); ERROR (context, "Failed to set the timeout.");
goto error_close; goto error_free;
} }
// Set the DTR line. // Set the DTR line.
status = dc_iostream_set_dtr (device->iostream, 1); status = dc_iostream_set_dtr (device->iostream, 1);
if (status != DC_STATUS_SUCCESS) { if (status != DC_STATUS_SUCCESS) {
ERROR (context, "Failed to set the DTR line."); ERROR (context, "Failed to set the DTR line.");
goto error_close; goto error_free;
} }
// Set the RTS line. // Set the RTS line.
status = dc_iostream_set_rts (device->iostream, 1); status = dc_iostream_set_rts (device->iostream, 1);
if (status != DC_STATUS_SUCCESS) { if (status != DC_STATUS_SUCCESS) {
ERROR (context, "Failed to set the RTS line."); ERROR (context, "Failed to set the RTS line.");
goto error_close; goto error_free;
} }
// Give the interface 100 ms to settle and draw power up. // Give the interface 100 ms to settle and draw power up.
@ -463,7 +455,7 @@ oceanic_vtpro_device_open (dc_device_t **out, dc_context_t *context, const char
// Initialize the data cable (MOD mode). // Initialize the data cable (MOD mode).
status = oceanic_vtpro_init (device); status = oceanic_vtpro_init (device);
if (status != DC_STATUS_SUCCESS) { if (status != DC_STATUS_SUCCESS) {
goto error_close; goto error_free;
} }
// Switch the device from surface mode into download mode. Before sending // Switch the device from surface mode into download mode. Before sending
@ -471,7 +463,7 @@ oceanic_vtpro_device_open (dc_device_t **out, dc_context_t *context, const char
// the user), or already in download mode. // the user), or already in download mode.
status = oceanic_vtpro_device_version ((dc_device_t *) device, device->base.version, sizeof (device->base.version)); status = oceanic_vtpro_device_version ((dc_device_t *) device, device->base.version, sizeof (device->base.version));
if (status != DC_STATUS_SUCCESS) { if (status != DC_STATUS_SUCCESS) {
goto error_close; goto error_free;
} }
// Calibrate the device. Although calibration is optional, it's highly // Calibrate the device. Although calibration is optional, it's highly
@ -479,7 +471,7 @@ oceanic_vtpro_device_open (dc_device_t **out, dc_context_t *context, const char
// when processing the command itself is quite slow. // when processing the command itself is quite slow.
status = oceanic_vtpro_calibrate (device); status = oceanic_vtpro_calibrate (device);
if (status != DC_STATUS_SUCCESS) { if (status != DC_STATUS_SUCCESS) {
goto error_close; goto error_free;
} }
// Override the base class values. // Override the base class values.
@ -498,8 +490,6 @@ oceanic_vtpro_device_open (dc_device_t **out, dc_context_t *context, const char
return DC_STATUS_SUCCESS; return DC_STATUS_SUCCESS;
error_close:
dc_iostream_close (device->iostream);
error_free: error_free:
dc_device_deallocate ((dc_device_t *) device); dc_device_deallocate ((dc_device_t *) device);
return status; return status;
@ -519,12 +509,6 @@ oceanic_vtpro_device_close (dc_device_t *abstract)
dc_status_set_error(&status, rc); dc_status_set_error(&status, rc);
} }
// Close the device.
rc = dc_iostream_close (device->iostream);
if (rc != DC_STATUS_SUCCESS) {
dc_status_set_error(&status, rc);
}
return status; return status;
} }

View File

@ -23,6 +23,7 @@
#define OCEANIC_VTPRO_H #define OCEANIC_VTPRO_H
#include <libdivecomputer/context.h> #include <libdivecomputer/context.h>
#include <libdivecomputer/iostream.h>
#include <libdivecomputer/device.h> #include <libdivecomputer/device.h>
#include <libdivecomputer/parser.h> #include <libdivecomputer/parser.h>
@ -33,7 +34,7 @@ extern "C" {
#endif /* __cplusplus */ #endif /* __cplusplus */
dc_status_t dc_status_t
oceanic_vtpro_device_open (dc_device_t **device, dc_context_t *context, const char *name, unsigned int model); oceanic_vtpro_device_open (dc_device_t **device, dc_context_t *context, dc_iostream_t *iostream, unsigned int model);
dc_status_t dc_status_t
oceanic_vtpro_parser_create (dc_parser_t **parser, dc_context_t *context, unsigned int model); oceanic_vtpro_parser_create (dc_parser_t **parser, dc_context_t *context, unsigned int model);

View File

@ -25,7 +25,6 @@
#include "reefnet_sensus.h" #include "reefnet_sensus.h"
#include "context-private.h" #include "context-private.h"
#include "device-private.h" #include "device-private.h"
#include "serial.h"
#include "checksum.h" #include "checksum.h"
#include "array.h" #include "array.h"
@ -86,7 +85,7 @@ reefnet_sensus_cancel (reefnet_sensus_device_t *device)
dc_status_t dc_status_t
reefnet_sensus_device_open (dc_device_t **out, dc_context_t *context, const char *name) reefnet_sensus_device_open (dc_device_t **out, dc_context_t *context, dc_iostream_t *iostream)
{ {
dc_status_t status = DC_STATUS_SUCCESS; dc_status_t status = DC_STATUS_SUCCESS;
reefnet_sensus_device_t *device = NULL; reefnet_sensus_device_t *device = NULL;
@ -102,32 +101,25 @@ reefnet_sensus_device_open (dc_device_t **out, dc_context_t *context, const char
} }
// Set the default values. // Set the default values.
device->iostream = NULL; device->iostream = iostream;
device->waiting = 0; device->waiting = 0;
device->timestamp = 0; device->timestamp = 0;
device->systime = (dc_ticks_t) -1; device->systime = (dc_ticks_t) -1;
device->devtime = 0; device->devtime = 0;
memset (device->handshake, 0, sizeof (device->handshake)); memset (device->handshake, 0, sizeof (device->handshake));
// Open the device.
status = dc_serial_open (&device->iostream, context, name);
if (status != DC_STATUS_SUCCESS) {
ERROR (context, "Failed to open the serial port.");
goto error_free;
}
// Set the serial communication protocol (19200 8N1). // Set the serial communication protocol (19200 8N1).
status = dc_iostream_configure (device->iostream, 19200, 8, DC_PARITY_NONE, DC_STOPBITS_ONE, DC_FLOWCONTROL_NONE); status = dc_iostream_configure (device->iostream, 19200, 8, DC_PARITY_NONE, DC_STOPBITS_ONE, DC_FLOWCONTROL_NONE);
if (status != DC_STATUS_SUCCESS) { if (status != DC_STATUS_SUCCESS) {
ERROR (context, "Failed to set the terminal attributes."); ERROR (context, "Failed to set the terminal attributes.");
goto error_close; goto error_free;
} }
// Set the timeout for receiving data (3000 ms). // Set the timeout for receiving data (3000 ms).
status = dc_iostream_set_timeout (device->iostream, 3000); status = dc_iostream_set_timeout (device->iostream, 3000);
if (status != DC_STATUS_SUCCESS) { if (status != DC_STATUS_SUCCESS) {
ERROR (context, "Failed to set the timeout."); ERROR (context, "Failed to set the timeout.");
goto error_close; goto error_free;
} }
// Make sure everything is in a sane state. // Make sure everything is in a sane state.
@ -137,8 +129,6 @@ reefnet_sensus_device_open (dc_device_t **out, dc_context_t *context, const char
return DC_STATUS_SUCCESS; return DC_STATUS_SUCCESS;
error_close:
dc_iostream_close (device->iostream);
error_free: error_free:
dc_device_deallocate ((dc_device_t *) device); dc_device_deallocate ((dc_device_t *) device);
return status; return status;
@ -161,12 +151,6 @@ reefnet_sensus_device_close (dc_device_t *abstract)
} }
} }
// Close the device.
rc = dc_iostream_close (device->iostream);
if (rc != DC_STATUS_SUCCESS) {
dc_status_set_error(&status, rc);
}
return status; return status;
} }

View File

@ -23,6 +23,7 @@
#define REEFNET_SENSUS_H #define REEFNET_SENSUS_H
#include <libdivecomputer/context.h> #include <libdivecomputer/context.h>
#include <libdivecomputer/iostream.h>
#include <libdivecomputer/device.h> #include <libdivecomputer/device.h>
#include <libdivecomputer/parser.h> #include <libdivecomputer/parser.h>
#include <libdivecomputer/reefnet_sensus.h> #include <libdivecomputer/reefnet_sensus.h>
@ -32,7 +33,7 @@ extern "C" {
#endif /* __cplusplus */ #endif /* __cplusplus */
dc_status_t dc_status_t
reefnet_sensus_device_open (dc_device_t **device, dc_context_t *context, const char *name); reefnet_sensus_device_open (dc_device_t **device, dc_context_t *context, dc_iostream_t *iostream);
dc_status_t dc_status_t
reefnet_sensus_parser_create (dc_parser_t **parser, dc_context_t *context, unsigned int devtime, dc_ticks_t systime); reefnet_sensus_parser_create (dc_parser_t **parser, dc_context_t *context, unsigned int devtime, dc_ticks_t systime);

View File

@ -25,7 +25,6 @@
#include "reefnet_sensuspro.h" #include "reefnet_sensuspro.h"
#include "context-private.h" #include "context-private.h"
#include "device-private.h" #include "device-private.h"
#include "serial.h"
#include "checksum.h" #include "checksum.h"
#include "array.h" #include "array.h"
@ -46,7 +45,6 @@ typedef struct reefnet_sensuspro_device_t {
static dc_status_t reefnet_sensuspro_device_set_fingerprint (dc_device_t *abstract, const unsigned char data[], unsigned int size); static dc_status_t reefnet_sensuspro_device_set_fingerprint (dc_device_t *abstract, const unsigned char data[], unsigned int size);
static dc_status_t reefnet_sensuspro_device_dump (dc_device_t *abstract, dc_buffer_t *buffer); static dc_status_t reefnet_sensuspro_device_dump (dc_device_t *abstract, dc_buffer_t *buffer);
static dc_status_t reefnet_sensuspro_device_foreach (dc_device_t *abstract, dc_dive_callback_t callback, void *userdata); static dc_status_t reefnet_sensuspro_device_foreach (dc_device_t *abstract, dc_dive_callback_t callback, void *userdata);
static dc_status_t reefnet_sensuspro_device_close (dc_device_t *abstract);
static const dc_device_vtable_t reefnet_sensuspro_device_vtable = { static const dc_device_vtable_t reefnet_sensuspro_device_vtable = {
sizeof(reefnet_sensuspro_device_t), sizeof(reefnet_sensuspro_device_t),
@ -57,14 +55,14 @@ static const dc_device_vtable_t reefnet_sensuspro_device_vtable = {
reefnet_sensuspro_device_dump, /* dump */ reefnet_sensuspro_device_dump, /* dump */
reefnet_sensuspro_device_foreach, /* foreach */ reefnet_sensuspro_device_foreach, /* foreach */
NULL, /* timesync */ NULL, /* timesync */
reefnet_sensuspro_device_close /* close */ NULL /* close */
}; };
static dc_status_t static dc_status_t
reefnet_sensuspro_extract_dives (dc_device_t *device, const unsigned char data[], unsigned int size, dc_dive_callback_t callback, void *userdata); reefnet_sensuspro_extract_dives (dc_device_t *device, const unsigned char data[], unsigned int size, dc_dive_callback_t callback, void *userdata);
dc_status_t dc_status_t
reefnet_sensuspro_device_open (dc_device_t **out, dc_context_t *context, const char *name) reefnet_sensuspro_device_open (dc_device_t **out, dc_context_t *context, dc_iostream_t *iostream)
{ {
dc_status_t status = DC_STATUS_SUCCESS; dc_status_t status = DC_STATUS_SUCCESS;
reefnet_sensuspro_device_t *device = NULL; reefnet_sensuspro_device_t *device = NULL;
@ -80,31 +78,24 @@ reefnet_sensuspro_device_open (dc_device_t **out, dc_context_t *context, const c
} }
// Set the default values. // Set the default values.
device->iostream = NULL; device->iostream = iostream;
device->timestamp = 0; device->timestamp = 0;
device->systime = (dc_ticks_t) -1; device->systime = (dc_ticks_t) -1;
device->devtime = 0; device->devtime = 0;
memset (device->handshake, 0, sizeof (device->handshake)); memset (device->handshake, 0, sizeof (device->handshake));
// Open the device.
status = dc_serial_open (&device->iostream, context, name);
if (status != DC_STATUS_SUCCESS) {
ERROR (context, "Failed to open the serial port.");
goto error_free;
}
// Set the serial communication protocol (19200 8N1). // Set the serial communication protocol (19200 8N1).
status = dc_iostream_configure (device->iostream, 19200, 8, DC_PARITY_NONE, DC_STOPBITS_ONE, DC_FLOWCONTROL_NONE); status = dc_iostream_configure (device->iostream, 19200, 8, DC_PARITY_NONE, DC_STOPBITS_ONE, DC_FLOWCONTROL_NONE);
if (status != DC_STATUS_SUCCESS) { if (status != DC_STATUS_SUCCESS) {
ERROR (context, "Failed to set the terminal attributes."); ERROR (context, "Failed to set the terminal attributes.");
goto error_close; goto error_free;
} }
// Set the timeout for receiving data (3000ms). // Set the timeout for receiving data (3000ms).
status = dc_iostream_set_timeout (device->iostream, 3000); status = dc_iostream_set_timeout (device->iostream, 3000);
if (status != DC_STATUS_SUCCESS) { if (status != DC_STATUS_SUCCESS) {
ERROR (context, "Failed to set the timeout."); ERROR (context, "Failed to set the timeout.");
goto error_close; goto error_free;
} }
// Make sure everything is in a sane state. // Make sure everything is in a sane state.
@ -114,31 +105,12 @@ reefnet_sensuspro_device_open (dc_device_t **out, dc_context_t *context, const c
return DC_STATUS_SUCCESS; return DC_STATUS_SUCCESS;
error_close:
dc_iostream_close (device->iostream);
error_free: error_free:
dc_device_deallocate ((dc_device_t *) device); dc_device_deallocate ((dc_device_t *) device);
return status; return status;
} }
static dc_status_t
reefnet_sensuspro_device_close (dc_device_t *abstract)
{
dc_status_t status = DC_STATUS_SUCCESS;
reefnet_sensuspro_device_t *device = (reefnet_sensuspro_device_t*) abstract;
dc_status_t rc = DC_STATUS_SUCCESS;
// Close the device.
rc = dc_iostream_close (device->iostream);
if (rc != DC_STATUS_SUCCESS) {
dc_status_set_error(&status, rc);
}
return status;
}
dc_status_t dc_status_t
reefnet_sensuspro_device_get_handshake (dc_device_t *abstract, unsigned char data[], unsigned int size) reefnet_sensuspro_device_get_handshake (dc_device_t *abstract, unsigned char data[], unsigned int size)
{ {

View File

@ -23,6 +23,7 @@
#define REEFNET_SENSUSPRO_H #define REEFNET_SENSUSPRO_H
#include <libdivecomputer/context.h> #include <libdivecomputer/context.h>
#include <libdivecomputer/iostream.h>
#include <libdivecomputer/device.h> #include <libdivecomputer/device.h>
#include <libdivecomputer/parser.h> #include <libdivecomputer/parser.h>
#include <libdivecomputer/reefnet_sensuspro.h> #include <libdivecomputer/reefnet_sensuspro.h>
@ -32,7 +33,7 @@ extern "C" {
#endif /* __cplusplus */ #endif /* __cplusplus */
dc_status_t dc_status_t
reefnet_sensuspro_device_open (dc_device_t **device, dc_context_t *context, const char *name); reefnet_sensuspro_device_open (dc_device_t **device, dc_context_t *context, dc_iostream_t *iostream);
dc_status_t dc_status_t
reefnet_sensuspro_parser_create (dc_parser_t **parser, dc_context_t *context, unsigned int devtime, dc_ticks_t systime); reefnet_sensuspro_parser_create (dc_parser_t **parser, dc_context_t *context, unsigned int devtime, dc_ticks_t systime);

View File

@ -26,7 +26,6 @@
#include "reefnet_sensusultra.h" #include "reefnet_sensusultra.h"
#include "context-private.h" #include "context-private.h"
#include "device-private.h" #include "device-private.h"
#include "serial.h"
#include "checksum.h" #include "checksum.h"
#include "array.h" #include "array.h"
@ -55,7 +54,6 @@ typedef struct reefnet_sensusultra_device_t {
static dc_status_t reefnet_sensusultra_device_set_fingerprint (dc_device_t *abstract, const unsigned char data[], unsigned int size); static dc_status_t reefnet_sensusultra_device_set_fingerprint (dc_device_t *abstract, const unsigned char data[], unsigned int size);
static dc_status_t reefnet_sensusultra_device_dump (dc_device_t *abstract, dc_buffer_t *buffer); static dc_status_t reefnet_sensusultra_device_dump (dc_device_t *abstract, dc_buffer_t *buffer);
static dc_status_t reefnet_sensusultra_device_foreach (dc_device_t *abstract, dc_dive_callback_t callback, void *userdata); static dc_status_t reefnet_sensusultra_device_foreach (dc_device_t *abstract, dc_dive_callback_t callback, void *userdata);
static dc_status_t reefnet_sensusultra_device_close (dc_device_t *abstract);
static const dc_device_vtable_t reefnet_sensusultra_device_vtable = { static const dc_device_vtable_t reefnet_sensusultra_device_vtable = {
sizeof(reefnet_sensusultra_device_t), sizeof(reefnet_sensusultra_device_t),
@ -66,12 +64,12 @@ static const dc_device_vtable_t reefnet_sensusultra_device_vtable = {
reefnet_sensusultra_device_dump, /* dump */ reefnet_sensusultra_device_dump, /* dump */
reefnet_sensusultra_device_foreach, /* foreach */ reefnet_sensusultra_device_foreach, /* foreach */
NULL, /* timesync */ NULL, /* timesync */
reefnet_sensusultra_device_close /* close */ NULL /* close */
}; };
dc_status_t dc_status_t
reefnet_sensusultra_device_open (dc_device_t **out, dc_context_t *context, const char *name) reefnet_sensusultra_device_open (dc_device_t **out, dc_context_t *context, dc_iostream_t *iostream)
{ {
dc_status_t status = DC_STATUS_SUCCESS; dc_status_t status = DC_STATUS_SUCCESS;
reefnet_sensusultra_device_t *device = NULL; reefnet_sensusultra_device_t *device = NULL;
@ -87,31 +85,24 @@ reefnet_sensusultra_device_open (dc_device_t **out, dc_context_t *context, const
} }
// Set the default values. // Set the default values.
device->iostream = NULL; device->iostream = iostream;
device->timestamp = 0; device->timestamp = 0;
device->systime = (dc_ticks_t) -1; device->systime = (dc_ticks_t) -1;
device->devtime = 0; device->devtime = 0;
memset (device->handshake, 0, sizeof (device->handshake)); memset (device->handshake, 0, sizeof (device->handshake));
// Open the device.
status = dc_serial_open (&device->iostream, context, name);
if (status != DC_STATUS_SUCCESS) {
ERROR (context, "Failed to open the serial port.");
goto error_free;
}
// Set the serial communication protocol (115200 8N1). // Set the serial communication protocol (115200 8N1).
status = dc_iostream_configure (device->iostream, 115200, 8, DC_PARITY_NONE, DC_STOPBITS_ONE, DC_FLOWCONTROL_NONE); status = dc_iostream_configure (device->iostream, 115200, 8, DC_PARITY_NONE, DC_STOPBITS_ONE, DC_FLOWCONTROL_NONE);
if (status != DC_STATUS_SUCCESS) { if (status != DC_STATUS_SUCCESS) {
ERROR (context, "Failed to set the terminal attributes."); ERROR (context, "Failed to set the terminal attributes.");
goto error_close; goto error_free;
} }
// Set the timeout for receiving data (3000ms). // Set the timeout for receiving data (3000ms).
status = dc_iostream_set_timeout (device->iostream, 3000); status = dc_iostream_set_timeout (device->iostream, 3000);
if (status != DC_STATUS_SUCCESS) { if (status != DC_STATUS_SUCCESS) {
ERROR (context, "Failed to set the timeout."); ERROR (context, "Failed to set the timeout.");
goto error_close; goto error_free;
} }
// Make sure everything is in a sane state. // Make sure everything is in a sane state.
@ -121,31 +112,12 @@ reefnet_sensusultra_device_open (dc_device_t **out, dc_context_t *context, const
return DC_STATUS_SUCCESS; return DC_STATUS_SUCCESS;
error_close:
dc_iostream_close (device->iostream);
error_free: error_free:
dc_device_deallocate ((dc_device_t *) device); dc_device_deallocate ((dc_device_t *) device);
return status; return status;
} }
static dc_status_t
reefnet_sensusultra_device_close (dc_device_t *abstract)
{
dc_status_t status = DC_STATUS_SUCCESS;
reefnet_sensusultra_device_t *device = (reefnet_sensusultra_device_t*) abstract;
dc_status_t rc = DC_STATUS_SUCCESS;
// Close the device.
rc = dc_iostream_close (device->iostream);
if (rc != DC_STATUS_SUCCESS) {
dc_status_set_error(&status, rc);
}
return status;
}
dc_status_t dc_status_t
reefnet_sensusultra_device_get_handshake (dc_device_t *abstract, unsigned char data[], unsigned int size) reefnet_sensusultra_device_get_handshake (dc_device_t *abstract, unsigned char data[], unsigned int size)
{ {

View File

@ -23,6 +23,7 @@
#define REEFNET_SENSUSULTRA_H #define REEFNET_SENSUSULTRA_H
#include <libdivecomputer/context.h> #include <libdivecomputer/context.h>
#include <libdivecomputer/iostream.h>
#include <libdivecomputer/device.h> #include <libdivecomputer/device.h>
#include <libdivecomputer/parser.h> #include <libdivecomputer/parser.h>
#include <libdivecomputer/reefnet_sensusultra.h> #include <libdivecomputer/reefnet_sensusultra.h>
@ -32,7 +33,7 @@ extern "C" {
#endif /* __cplusplus */ #endif /* __cplusplus */
dc_status_t dc_status_t
reefnet_sensusultra_device_open (dc_device_t **device, dc_context_t *context, const char *name); reefnet_sensusultra_device_open (dc_device_t **device, dc_context_t *context, dc_iostream_t *iostream);
dc_status_t dc_status_t
reefnet_sensusultra_parser_create (dc_parser_t **parser, dc_context_t *context, unsigned int devtime, dc_ticks_t systime); reefnet_sensusultra_parser_create (dc_parser_t **parser, dc_context_t *context, unsigned int devtime, dc_ticks_t systime);

View File

@ -52,7 +52,7 @@
#define NOPTY 1 #define NOPTY 1
#endif #endif
#include "serial.h" #include <libdivecomputer/serial.h>
#include "common-private.h" #include "common-private.h"
#include "context-private.h" #include "context-private.h"
@ -271,7 +271,7 @@ dc_serial_open (dc_iostream_t **out, dc_context_t *context, const char *name)
INFO (context, "Open: name=%s", name); INFO (context, "Open: name=%s", name);
// Allocate memory. // Allocate memory.
device = (dc_serial_t *) dc_iostream_allocate (context, &dc_serial_vtable); device = (dc_serial_t *) dc_iostream_allocate (context, &dc_serial_vtable, DC_TRANSPORT_SERIAL);
if (device == NULL) { if (device == NULL) {
SYSERROR (context, ENOMEM); SYSERROR (context, ENOMEM);
return DC_STATUS_NOMEMORY; return DC_STATUS_NOMEMORY;

View File

@ -24,7 +24,7 @@
#define NOGDI #define NOGDI
#include <windows.h> #include <windows.h>
#include "serial.h" #include <libdivecomputer/serial.h>
#include "common-private.h" #include "common-private.h"
#include "context-private.h" #include "context-private.h"
@ -276,7 +276,7 @@ dc_serial_open (dc_iostream_t **out, dc_context_t *context, const char *name)
} }
// Allocate memory. // Allocate memory.
device = (dc_serial_t *) dc_iostream_allocate (context, &dc_serial_vtable); device = (dc_serial_t *) dc_iostream_allocate (context, &dc_serial_vtable, DC_TRANSPORT_SERIAL);
if (device == NULL) { if (device == NULL) {
SYSERROR (context, ERROR_OUTOFMEMORY); SYSERROR (context, ERROR_OUTOFMEMORY);
return DC_STATUS_NOMEMORY; return DC_STATUS_NOMEMORY;

View File

@ -36,29 +36,24 @@
#define ESC_ESC 0xDD #define ESC_ESC 0xDD
dc_status_t dc_status_t
shearwater_common_open (shearwater_common_device_t *device, dc_context_t *context, const char *name) shearwater_common_setup (shearwater_common_device_t *device, dc_context_t *context, dc_iostream_t *iostream)
{ {
dc_status_t status = DC_STATUS_SUCCESS; dc_status_t status = DC_STATUS_SUCCESS;
// Open the device. device->iostream = iostream;
status = dc_serial_open (&device->iostream, context, name);
if (status != DC_STATUS_SUCCESS) {
ERROR (context, "Failed to open the serial port.");
return status;
}
// Set the serial communication protocol (115200 8N1). // Set the serial communication protocol (115200 8N1).
status = dc_iostream_configure (device->iostream, 115200, 8, DC_PARITY_NONE, DC_STOPBITS_ONE, DC_FLOWCONTROL_NONE); status = dc_iostream_configure (device->iostream, 115200, 8, DC_PARITY_NONE, DC_STOPBITS_ONE, DC_FLOWCONTROL_NONE);
if (status != DC_STATUS_SUCCESS) { if (status != DC_STATUS_SUCCESS) {
ERROR (context, "Failed to set the terminal attributes."); ERROR (context, "Failed to set the terminal attributes.");
goto error_close; return status;
} }
// Set the timeout for receiving data (3000ms). // Set the timeout for receiving data (3000ms).
status = dc_iostream_set_timeout (device->iostream, 3000); status = dc_iostream_set_timeout (device->iostream, 3000);
if (status != DC_STATUS_SUCCESS) { if (status != DC_STATUS_SUCCESS) {
ERROR (context, "Failed to set the timeout."); ERROR (context, "Failed to set the timeout.");
goto error_close; return status;
} }
// Make sure everything is in a sane state. // Make sure everything is in a sane state.
@ -66,18 +61,6 @@ shearwater_common_open (shearwater_common_device_t *device, dc_context_t *contex
dc_iostream_purge (device->iostream, DC_DIRECTION_ALL); dc_iostream_purge (device->iostream, DC_DIRECTION_ALL);
return DC_STATUS_SUCCESS; return DC_STATUS_SUCCESS;
error_close:
dc_iostream_close (device->iostream);
return status;
}
dc_status_t
shearwater_common_close (shearwater_common_device_t *device)
{
// Close the device.
return dc_iostream_close (device->iostream);
} }

View File

@ -22,8 +22,9 @@
#ifndef SHEARWATER_COMMON_H #ifndef SHEARWATER_COMMON_H
#define SHEARWATER_COMMON_H #define SHEARWATER_COMMON_H
#include <libdivecomputer/iostream.h>
#include "device-private.h" #include "device-private.h"
#include "serial.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
@ -49,10 +50,7 @@ typedef struct shearwater_common_device_t {
} shearwater_common_device_t; } shearwater_common_device_t;
dc_status_t dc_status_t
shearwater_common_open (shearwater_common_device_t *device, dc_context_t *context, const char *name); shearwater_common_setup (shearwater_common_device_t *device, dc_context_t *context, dc_iostream_t *iostream);
dc_status_t
shearwater_common_close (shearwater_common_device_t *device);
dc_status_t dc_status_t
shearwater_common_transfer (shearwater_common_device_t *device, const unsigned char input[], unsigned int isize, unsigned char output[], unsigned int osize, unsigned int *actual); shearwater_common_transfer (shearwater_common_device_t *device, const unsigned char input[], unsigned int isize, unsigned char output[], unsigned int osize, unsigned int *actual);

View File

@ -77,7 +77,7 @@ str2num (unsigned char data[], unsigned int size, unsigned int offset)
dc_status_t dc_status_t
shearwater_petrel_device_open (dc_device_t **out, dc_context_t *context, const char *name) shearwater_petrel_device_open (dc_device_t **out, dc_context_t *context, dc_iostream_t *iostream)
{ {
dc_status_t status = DC_STATUS_SUCCESS; dc_status_t status = DC_STATUS_SUCCESS;
shearwater_petrel_device_t *device = NULL; shearwater_petrel_device_t *device = NULL;
@ -95,8 +95,8 @@ shearwater_petrel_device_open (dc_device_t **out, dc_context_t *context, const c
// Set the default values. // Set the default values.
memset (device->fingerprint, 0, sizeof (device->fingerprint)); memset (device->fingerprint, 0, sizeof (device->fingerprint));
// Open the device. // Setup the device.
status = shearwater_common_open (&device->base, context, name); status = shearwater_common_setup (&device->base, context, iostream);
if (status != DC_STATUS_SUCCESS) { if (status != DC_STATUS_SUCCESS) {
goto error_free; goto error_free;
} }
@ -125,12 +125,6 @@ shearwater_petrel_device_close (dc_device_t *abstract)
dc_status_set_error(&status, rc); dc_status_set_error(&status, rc);
} }
// Close the device.
rc = shearwater_common_close (device);
if (rc != DC_STATUS_SUCCESS) {
dc_status_set_error(&status, rc);
}
return status; return status;
} }

View File

@ -23,6 +23,7 @@
#define SHEARWATER_PETREL_H #define SHEARWATER_PETREL_H
#include <libdivecomputer/context.h> #include <libdivecomputer/context.h>
#include <libdivecomputer/iostream.h>
#include <libdivecomputer/device.h> #include <libdivecomputer/device.h>
#include <libdivecomputer/parser.h> #include <libdivecomputer/parser.h>
@ -31,7 +32,7 @@ extern "C" {
#endif /* __cplusplus */ #endif /* __cplusplus */
dc_status_t dc_status_t
shearwater_petrel_device_open (dc_device_t **device, dc_context_t *context, const char *name); shearwater_petrel_device_open (dc_device_t **device, dc_context_t *context, dc_iostream_t *iostream);
dc_status_t dc_status_t
shearwater_petrel_parser_create (dc_parser_t **parser, dc_context_t *context, unsigned int model); shearwater_petrel_parser_create (dc_parser_t **parser, dc_context_t *context, unsigned int model);

View File

@ -44,7 +44,6 @@ typedef struct shearwater_predator_device_t {
static dc_status_t shearwater_predator_device_set_fingerprint (dc_device_t *abstract, const unsigned char data[], unsigned int size); static dc_status_t shearwater_predator_device_set_fingerprint (dc_device_t *abstract, const unsigned char data[], unsigned int size);
static dc_status_t shearwater_predator_device_dump (dc_device_t *abstract, dc_buffer_t *buffer); static dc_status_t shearwater_predator_device_dump (dc_device_t *abstract, dc_buffer_t *buffer);
static dc_status_t shearwater_predator_device_foreach (dc_device_t *abstract, dc_dive_callback_t callback, void *userdata); static dc_status_t shearwater_predator_device_foreach (dc_device_t *abstract, dc_dive_callback_t callback, void *userdata);
static dc_status_t shearwater_predator_device_close (dc_device_t *abstract);
static const dc_device_vtable_t shearwater_predator_device_vtable = { static const dc_device_vtable_t shearwater_predator_device_vtable = {
sizeof(shearwater_predator_device_t), sizeof(shearwater_predator_device_t),
@ -55,14 +54,14 @@ static const dc_device_vtable_t shearwater_predator_device_vtable = {
shearwater_predator_device_dump, /* dump */ shearwater_predator_device_dump, /* dump */
shearwater_predator_device_foreach, /* foreach */ shearwater_predator_device_foreach, /* foreach */
NULL, /* timesync */ NULL, /* timesync */
shearwater_predator_device_close /* close */ NULL /* close */
}; };
static dc_status_t static dc_status_t
shearwater_predator_extract_dives (dc_device_t *device, const unsigned char data[], unsigned int size, dc_dive_callback_t callback, void *userdata); shearwater_predator_extract_dives (dc_device_t *device, const unsigned char data[], unsigned int size, dc_dive_callback_t callback, void *userdata);
dc_status_t dc_status_t
shearwater_predator_device_open (dc_device_t **out, dc_context_t *context, const char *name) shearwater_predator_device_open (dc_device_t **out, dc_context_t *context, dc_iostream_t *iostream)
{ {
dc_status_t status = DC_STATUS_SUCCESS; dc_status_t status = DC_STATUS_SUCCESS;
shearwater_predator_device_t *device = NULL; shearwater_predator_device_t *device = NULL;
@ -80,8 +79,8 @@ shearwater_predator_device_open (dc_device_t **out, dc_context_t *context, const
// Set the default values. // Set the default values.
memset (device->fingerprint, 0, sizeof (device->fingerprint)); memset (device->fingerprint, 0, sizeof (device->fingerprint));
// Open the device. // Setup the device.
status = shearwater_common_open (&device->base, context, name); status = shearwater_common_setup (&device->base, context, iostream);
if (status != DC_STATUS_SUCCESS) { if (status != DC_STATUS_SUCCESS) {
goto error_free; goto error_free;
} }
@ -96,15 +95,6 @@ error_free:
} }
static dc_status_t
shearwater_predator_device_close (dc_device_t *abstract)
{
shearwater_common_device_t *device = (shearwater_common_device_t *) abstract;
return shearwater_common_close (device);
}
static dc_status_t static dc_status_t
shearwater_predator_device_set_fingerprint (dc_device_t *abstract, const unsigned char data[], unsigned int size) shearwater_predator_device_set_fingerprint (dc_device_t *abstract, const unsigned char data[], unsigned int size)
{ {

View File

@ -23,6 +23,7 @@
#define SHEARWATER_PREDATOR_H #define SHEARWATER_PREDATOR_H
#include <libdivecomputer/context.h> #include <libdivecomputer/context.h>
#include <libdivecomputer/iostream.h>
#include <libdivecomputer/device.h> #include <libdivecomputer/device.h>
#include <libdivecomputer/parser.h> #include <libdivecomputer/parser.h>
@ -31,7 +32,7 @@ extern "C" {
#endif /* __cplusplus */ #endif /* __cplusplus */
dc_status_t dc_status_t
shearwater_predator_device_open (dc_device_t **device, dc_context_t *context, const char *name); shearwater_predator_device_open (dc_device_t **device, dc_context_t *context, dc_iostream_t *iostream);
dc_status_t dc_status_t
shearwater_predator_parser_create (dc_parser_t **parser, dc_context_t *context, unsigned int model); shearwater_predator_parser_create (dc_parser_t **parser, dc_context_t *context, unsigned int model);

View File

@ -26,7 +26,6 @@
#include "suunto_d9.h" #include "suunto_d9.h"
#include "suunto_common2.h" #include "suunto_common2.h"
#include "context-private.h" #include "context-private.h"
#include "serial.h"
#include "checksum.h" #include "checksum.h"
#include "array.h" #include "array.h"
@ -48,7 +47,6 @@ typedef struct suunto_d9_device_t {
} suunto_d9_device_t; } suunto_d9_device_t;
static dc_status_t suunto_d9_device_packet (dc_device_t *abstract, const unsigned char command[], unsigned int csize, unsigned char answer[], unsigned int asize, unsigned int size); static dc_status_t suunto_d9_device_packet (dc_device_t *abstract, const unsigned char command[], unsigned int csize, unsigned char answer[], unsigned int asize, unsigned int size);
static dc_status_t suunto_d9_device_close (dc_device_t *abstract);
static const suunto_common2_device_vtable_t suunto_d9_device_vtable = { static const suunto_common2_device_vtable_t suunto_d9_device_vtable = {
{ {
@ -60,7 +58,7 @@ static const suunto_common2_device_vtable_t suunto_d9_device_vtable = {
suunto_common2_device_dump, /* dump */ suunto_common2_device_dump, /* dump */
suunto_common2_device_foreach, /* foreach */ suunto_common2_device_foreach, /* foreach */
NULL, /* timesync */ NULL, /* timesync */
suunto_d9_device_close /* close */ NULL /* close */
}, },
suunto_d9_device_packet suunto_d9_device_packet
}; };
@ -128,7 +126,7 @@ suunto_d9_device_autodetect (suunto_d9_device_t *device, unsigned int model)
dc_status_t dc_status_t
suunto_d9_device_open (dc_device_t **out, dc_context_t *context, const char *name, unsigned int model) suunto_d9_device_open (dc_device_t **out, dc_context_t *context, dc_iostream_t *iostream, unsigned int model)
{ {
dc_status_t status = DC_STATUS_SUCCESS; dc_status_t status = DC_STATUS_SUCCESS;
suunto_d9_device_t *device = NULL; suunto_d9_device_t *device = NULL;
@ -147,34 +145,27 @@ suunto_d9_device_open (dc_device_t **out, dc_context_t *context, const char *nam
suunto_common2_device_init (&device->base); suunto_common2_device_init (&device->base);
// Set the default values. // Set the default values.
device->iostream = NULL; device->iostream = iostream;
// Open the device.
status = dc_serial_open (&device->iostream, context, name);
if (status != DC_STATUS_SUCCESS) {
ERROR (context, "Failed to open the serial port.");
goto error_free;
}
// Set the serial communication protocol (9600 8N1). // Set the serial communication protocol (9600 8N1).
status = dc_iostream_configure (device->iostream, 9600, 8, DC_PARITY_NONE, DC_STOPBITS_ONE, DC_FLOWCONTROL_NONE); status = dc_iostream_configure (device->iostream, 9600, 8, DC_PARITY_NONE, DC_STOPBITS_ONE, DC_FLOWCONTROL_NONE);
if (status != DC_STATUS_SUCCESS) { if (status != DC_STATUS_SUCCESS) {
ERROR (context, "Failed to set the terminal attributes."); ERROR (context, "Failed to set the terminal attributes.");
goto error_close; goto error_free;
} }
// Set the timeout for receiving data (3000 ms). // Set the timeout for receiving data (3000 ms).
status = dc_iostream_set_timeout (device->iostream, 3000); status = dc_iostream_set_timeout (device->iostream, 3000);
if (status != DC_STATUS_SUCCESS) { if (status != DC_STATUS_SUCCESS) {
ERROR (context, "Failed to set the timeout."); ERROR (context, "Failed to set the timeout.");
goto error_close; goto error_free;
} }
// Set the DTR line (power supply for the interface). // Set the DTR line (power supply for the interface).
status = dc_iostream_set_dtr (device->iostream, 1); status = dc_iostream_set_dtr (device->iostream, 1);
if (status != DC_STATUS_SUCCESS) { if (status != DC_STATUS_SUCCESS) {
ERROR (context, "Failed to set the DTR line."); ERROR (context, "Failed to set the DTR line.");
goto error_close; goto error_free;
} }
// Give the interface 100 ms to settle and draw power up. // Give the interface 100 ms to settle and draw power up.
@ -187,7 +178,7 @@ suunto_d9_device_open (dc_device_t **out, dc_context_t *context, const char *nam
status = suunto_d9_device_autodetect (device, model); status = suunto_d9_device_autodetect (device, model);
if (status != DC_STATUS_SUCCESS) { if (status != DC_STATUS_SUCCESS) {
ERROR (context, "Failed to identify the protocol variant."); ERROR (context, "Failed to identify the protocol variant.");
goto error_close; goto error_free;
} }
// Override the base class values. // Override the base class values.
@ -205,31 +196,12 @@ suunto_d9_device_open (dc_device_t **out, dc_context_t *context, const char *nam
return DC_STATUS_SUCCESS; return DC_STATUS_SUCCESS;
error_close:
dc_iostream_close (device->iostream);
error_free: error_free:
dc_device_deallocate ((dc_device_t *) device); dc_device_deallocate ((dc_device_t *) device);
return status; return status;
} }
static dc_status_t
suunto_d9_device_close (dc_device_t *abstract)
{
dc_status_t status = DC_STATUS_SUCCESS;
suunto_d9_device_t *device = (suunto_d9_device_t*) abstract;
dc_status_t rc = DC_STATUS_SUCCESS;
// Close the device.
rc = dc_iostream_close (device->iostream);
if (rc != DC_STATUS_SUCCESS) {
dc_status_set_error(&status, rc);
}
return status;
}
static dc_status_t static dc_status_t
suunto_d9_device_packet (dc_device_t *abstract, const unsigned char command[], unsigned int csize, unsigned char answer[], unsigned int asize, unsigned int size) suunto_d9_device_packet (dc_device_t *abstract, const unsigned char command[], unsigned int csize, unsigned char answer[], unsigned int asize, unsigned int size)
{ {

View File

@ -23,6 +23,7 @@
#define SUUNTO_D9_H #define SUUNTO_D9_H
#include <libdivecomputer/context.h> #include <libdivecomputer/context.h>
#include <libdivecomputer/iostream.h>
#include <libdivecomputer/device.h> #include <libdivecomputer/device.h>
#include <libdivecomputer/parser.h> #include <libdivecomputer/parser.h>
#include <libdivecomputer/suunto_d9.h> #include <libdivecomputer/suunto_d9.h>
@ -32,7 +33,7 @@ extern "C" {
#endif /* __cplusplus */ #endif /* __cplusplus */
dc_status_t dc_status_t
suunto_d9_device_open (dc_device_t **device, dc_context_t *context, const char *name, unsigned int model); suunto_d9_device_open (dc_device_t **device, dc_context_t *context, dc_iostream_t *iostream, unsigned int model);
dc_status_t dc_status_t
suunto_d9_parser_create (dc_parser_t **parser, dc_context_t *context, unsigned int model); suunto_d9_parser_create (dc_parser_t **parser, dc_context_t *context, unsigned int model);

View File

@ -26,7 +26,6 @@
#include "suunto_common.h" #include "suunto_common.h"
#include "context-private.h" #include "context-private.h"
#include "device-private.h" #include "device-private.h"
#include "serial.h"
#include "checksum.h" #include "checksum.h"
#include "array.h" #include "array.h"
@ -41,7 +40,6 @@ typedef struct suunto_eon_device_t {
static dc_status_t suunto_eon_device_dump (dc_device_t *abstract, dc_buffer_t *buffer); static dc_status_t suunto_eon_device_dump (dc_device_t *abstract, dc_buffer_t *buffer);
static dc_status_t suunto_eon_device_foreach (dc_device_t *abstract, dc_dive_callback_t callback, void *userdata); static dc_status_t suunto_eon_device_foreach (dc_device_t *abstract, dc_dive_callback_t callback, void *userdata);
static dc_status_t suunto_eon_device_close (dc_device_t *abstract);
static const dc_device_vtable_t suunto_eon_device_vtable = { static const dc_device_vtable_t suunto_eon_device_vtable = {
sizeof(suunto_eon_device_t), sizeof(suunto_eon_device_t),
@ -52,7 +50,7 @@ static const dc_device_vtable_t suunto_eon_device_vtable = {
suunto_eon_device_dump, /* dump */ suunto_eon_device_dump, /* dump */
suunto_eon_device_foreach, /* foreach */ suunto_eon_device_foreach, /* foreach */
NULL, /* timesync */ NULL, /* timesync */
suunto_eon_device_close /* close */ NULL /* close */
}; };
static const suunto_common_layout_t suunto_eon_layout = { static const suunto_common_layout_t suunto_eon_layout = {
@ -65,7 +63,7 @@ static const suunto_common_layout_t suunto_eon_layout = {
dc_status_t dc_status_t
suunto_eon_device_open (dc_device_t **out, dc_context_t *context, const char *name) suunto_eon_device_open (dc_device_t **out, dc_context_t *context, dc_iostream_t *iostream)
{ {
dc_status_t status = DC_STATUS_SUCCESS; dc_status_t status = DC_STATUS_SUCCESS;
suunto_eon_device_t *device = NULL; suunto_eon_device_t *device = NULL;
@ -84,65 +82,39 @@ suunto_eon_device_open (dc_device_t **out, dc_context_t *context, const char *na
suunto_common_device_init (&device->base); suunto_common_device_init (&device->base);
// Set the default values. // Set the default values.
device->iostream = NULL; device->iostream = iostream;
// Open the device.
status = dc_serial_open (&device->iostream, context, name);
if (status != DC_STATUS_SUCCESS) {
ERROR (context, "Failed to open the serial port.");
goto error_free;
}
// Set the serial communication protocol (1200 8N2). // Set the serial communication protocol (1200 8N2).
status = dc_iostream_configure (device->iostream, 1200, 8, DC_PARITY_NONE, DC_STOPBITS_TWO, DC_FLOWCONTROL_NONE); status = dc_iostream_configure (device->iostream, 1200, 8, DC_PARITY_NONE, DC_STOPBITS_TWO, DC_FLOWCONTROL_NONE);
if (status != DC_STATUS_SUCCESS) { if (status != DC_STATUS_SUCCESS) {
ERROR (context, "Failed to set the terminal attributes."); ERROR (context, "Failed to set the terminal attributes.");
goto error_close; goto error_free;
} }
// Set the timeout for receiving data (1000ms). // Set the timeout for receiving data (1000ms).
status = dc_iostream_set_timeout (device->iostream, 1000); status = dc_iostream_set_timeout (device->iostream, 1000);
if (status != DC_STATUS_SUCCESS) { if (status != DC_STATUS_SUCCESS) {
ERROR (context, "Failed to set the timeout."); ERROR (context, "Failed to set the timeout.");
goto error_close; goto error_free;
} }
// Clear the RTS line. // Clear the RTS line.
status = dc_iostream_set_rts (device->iostream, 0); status = dc_iostream_set_rts (device->iostream, 0);
if (status != DC_STATUS_SUCCESS) { if (status != DC_STATUS_SUCCESS) {
ERROR (context, "Failed to set the DTR/RTS line."); ERROR (context, "Failed to set the DTR/RTS line.");
goto error_close; goto error_free;
} }
*out = (dc_device_t*) device; *out = (dc_device_t*) device;
return DC_STATUS_SUCCESS; return DC_STATUS_SUCCESS;
error_close:
dc_iostream_close (device->iostream);
error_free: error_free:
dc_device_deallocate ((dc_device_t *) device); dc_device_deallocate ((dc_device_t *) device);
return status; return status;
} }
static dc_status_t
suunto_eon_device_close (dc_device_t *abstract)
{
dc_status_t status = DC_STATUS_SUCCESS;
suunto_eon_device_t *device = (suunto_eon_device_t*) abstract;
dc_status_t rc = DC_STATUS_SUCCESS;
// Close the device.
rc = dc_iostream_close (device->iostream);
if (rc != DC_STATUS_SUCCESS) {
dc_status_set_error(&status, rc);
}
return status;
}
static dc_status_t static dc_status_t
suunto_eon_device_dump (dc_device_t *abstract, dc_buffer_t *buffer) suunto_eon_device_dump (dc_device_t *abstract, dc_buffer_t *buffer)
{ {

View File

@ -23,6 +23,7 @@
#define SUUNTO_EON_H #define SUUNTO_EON_H
#include <libdivecomputer/context.h> #include <libdivecomputer/context.h>
#include <libdivecomputer/iostream.h>
#include <libdivecomputer/device.h> #include <libdivecomputer/device.h>
#include <libdivecomputer/parser.h> #include <libdivecomputer/parser.h>
#include <libdivecomputer/suunto_eon.h> #include <libdivecomputer/suunto_eon.h>
@ -32,7 +33,7 @@ extern "C" {
#endif /* __cplusplus */ #endif /* __cplusplus */
dc_status_t dc_status_t
suunto_eon_device_open (dc_device_t **device, dc_context_t *context, const char *name); suunto_eon_device_open (dc_device_t **device, dc_context_t *context, dc_iostream_t *iostream);
dc_status_t dc_status_t
suunto_eon_parser_create (dc_parser_t **parser, dc_context_t *context, int spyder); suunto_eon_parser_create (dc_parser_t **parser, dc_context_t *context, int spyder);

View File

@ -27,7 +27,6 @@
#include "context-private.h" #include "context-private.h"
#include "device-private.h" #include "device-private.h"
#include "array.h" #include "array.h"
#include "usbhid.h"
#include "platform.h" #include "platform.h"
#define EONSTEEL 0 #define EONSTEEL 0
@ -81,7 +80,6 @@ struct directory_entry {
static dc_status_t suunto_eonsteel_device_set_fingerprint (dc_device_t *abstract, const unsigned char data[], unsigned int size); static dc_status_t suunto_eonsteel_device_set_fingerprint (dc_device_t *abstract, const unsigned char data[], unsigned int size);
static dc_status_t suunto_eonsteel_device_foreach(dc_device_t *abstract, dc_dive_callback_t callback, void *userdata); static dc_status_t suunto_eonsteel_device_foreach(dc_device_t *abstract, dc_dive_callback_t callback, void *userdata);
static dc_status_t suunto_eonsteel_device_timesync(dc_device_t *abstract, const dc_datetime_t *datetime); static dc_status_t suunto_eonsteel_device_timesync(dc_device_t *abstract, const dc_datetime_t *datetime);
static dc_status_t suunto_eonsteel_device_close(dc_device_t *abstract);
static const dc_device_vtable_t suunto_eonsteel_device_vtable = { static const dc_device_vtable_t suunto_eonsteel_device_vtable = {
sizeof(suunto_eonsteel_device_t), sizeof(suunto_eonsteel_device_t),
@ -92,7 +90,7 @@ static const dc_device_vtable_t suunto_eonsteel_device_vtable = {
NULL, /* dump */ NULL, /* dump */
suunto_eonsteel_device_foreach, /* foreach */ suunto_eonsteel_device_foreach, /* foreach */
suunto_eonsteel_device_timesync, /* timesync */ suunto_eonsteel_device_timesync, /* timesync */
suunto_eonsteel_device_close /* close */ NULL /* close */
}; };
static const char dive_directory[] = "0:/dives"; static const char dive_directory[] = "0:/dives";
@ -534,7 +532,7 @@ get_file_list(suunto_eonsteel_device_t *eon, struct directory_entry **res)
} }
dc_status_t dc_status_t
suunto_eonsteel_device_open(dc_device_t **out, dc_context_t *context, unsigned int model) suunto_eonsteel_device_open(dc_device_t **out, dc_context_t *context, dc_iostream_t *iostream, unsigned int model)
{ {
dc_status_t status = DC_STATUS_SUCCESS; dc_status_t status = DC_STATUS_SUCCESS;
suunto_eonsteel_device_t *eon = NULL; suunto_eonsteel_device_t *eon = NULL;
@ -547,28 +545,17 @@ suunto_eonsteel_device_open(dc_device_t **out, dc_context_t *context, unsigned i
return DC_STATUS_NOMEMORY; return DC_STATUS_NOMEMORY;
// Set up the magic handshake fields // Set up the magic handshake fields
eon->iostream = iostream;
eon->model = model; eon->model = model;
eon->magic = INIT_MAGIC; eon->magic = INIT_MAGIC;
eon->seq = INIT_SEQ; eon->seq = INIT_SEQ;
memset (eon->version, 0, sizeof (eon->version)); memset (eon->version, 0, sizeof (eon->version));
memset (eon->fingerprint, 0, sizeof (eon->fingerprint)); memset (eon->fingerprint, 0, sizeof (eon->fingerprint));
unsigned int vid = 0x1493, pid = 0;
if (model == EONCORE) {
pid = 0x0033;
} else {
pid = 0x0030;
}
status = dc_usbhid_open(&eon->iostream, context, vid, pid);
if (status != DC_STATUS_SUCCESS) {
ERROR(context, "unable to open device");
goto error_free;
}
status = dc_iostream_set_timeout(eon->iostream, 5000); status = dc_iostream_set_timeout(eon->iostream, 5000);
if (status != DC_STATUS_SUCCESS) { if (status != DC_STATUS_SUCCESS) {
ERROR (context, "Failed to set the timeout."); ERROR (context, "Failed to set the timeout.");
goto error_close; goto error_free;
} }
const unsigned char init[] = {0x02, 0x00, 0x2a, 0x00}; const unsigned char init[] = {0x02, 0x00, 0x2a, 0x00};
@ -576,15 +563,13 @@ suunto_eonsteel_device_open(dc_device_t **out, dc_context_t *context, unsigned i
init, sizeof(init), eon->version, sizeof(eon->version), NULL); init, sizeof(init), eon->version, sizeof(eon->version), NULL);
if (status != DC_STATUS_SUCCESS) { if (status != DC_STATUS_SUCCESS) {
ERROR(context, "unable to initialize device"); ERROR(context, "unable to initialize device");
goto error_close; goto error_free;
} }
*out = (dc_device_t *) eon; *out = (dc_device_t *) eon;
return DC_STATUS_SUCCESS; return DC_STATUS_SUCCESS;
error_close:
dc_iostream_close(eon->iostream);
error_free: error_free:
free(eon); free(eon);
return status; return status;
@ -777,13 +762,3 @@ static dc_status_t suunto_eonsteel_device_timesync(dc_device_t *abstract, const
return DC_STATUS_SUCCESS; return DC_STATUS_SUCCESS;
} }
static dc_status_t
suunto_eonsteel_device_close(dc_device_t *abstract)
{
suunto_eonsteel_device_t *eon = (suunto_eonsteel_device_t *) abstract;
dc_iostream_close(eon->iostream);
return DC_STATUS_SUCCESS;
}

View File

@ -23,6 +23,7 @@
#define SUUNTO_EONSTEEL_H #define SUUNTO_EONSTEEL_H
#include <libdivecomputer/context.h> #include <libdivecomputer/context.h>
#include <libdivecomputer/iostream.h>
#include <libdivecomputer/device.h> #include <libdivecomputer/device.h>
#include <libdivecomputer/parser.h> #include <libdivecomputer/parser.h>
@ -31,7 +32,7 @@ extern "C" {
#endif /* __cplusplus */ #endif /* __cplusplus */
dc_status_t dc_status_t
suunto_eonsteel_device_open(dc_device_t **device, dc_context_t *context, unsigned int model); suunto_eonsteel_device_open(dc_device_t **device, dc_context_t *context, dc_iostream_t *iostream, unsigned int model);
dc_status_t dc_status_t
suunto_eonsteel_parser_create(dc_parser_t **parser, dc_context_t *context, unsigned int model); suunto_eonsteel_parser_create(dc_parser_t **parser, dc_context_t *context, unsigned int model);

View File

@ -27,7 +27,6 @@
#include "context-private.h" #include "context-private.h"
#include "device-private.h" #include "device-private.h"
#include "ringbuffer.h" #include "ringbuffer.h"
#include "serial.h"
#include "array.h" #include "array.h"
#define ISINSTANCE(device) dc_device_isinstance((device), &suunto_solution_device_vtable) #define ISINSTANCE(device) dc_device_isinstance((device), &suunto_solution_device_vtable)
@ -44,7 +43,6 @@ typedef struct suunto_solution_device_t {
static dc_status_t suunto_solution_device_dump (dc_device_t *abstract, dc_buffer_t *buffer); static dc_status_t suunto_solution_device_dump (dc_device_t *abstract, dc_buffer_t *buffer);
static dc_status_t suunto_solution_device_foreach (dc_device_t *abstract, dc_dive_callback_t callback, void *userdata); static dc_status_t suunto_solution_device_foreach (dc_device_t *abstract, dc_dive_callback_t callback, void *userdata);
static dc_status_t suunto_solution_device_close (dc_device_t *abstract);
static const dc_device_vtable_t suunto_solution_device_vtable = { static const dc_device_vtable_t suunto_solution_device_vtable = {
sizeof(suunto_solution_device_t), sizeof(suunto_solution_device_t),
@ -55,14 +53,14 @@ static const dc_device_vtable_t suunto_solution_device_vtable = {
suunto_solution_device_dump, /* dump */ suunto_solution_device_dump, /* dump */
suunto_solution_device_foreach, /* foreach */ suunto_solution_device_foreach, /* foreach */
NULL, /* timesync */ NULL, /* timesync */
suunto_solution_device_close /* close */ NULL /* close */
}; };
static dc_status_t static dc_status_t
suunto_solution_extract_dives (dc_device_t *device, const unsigned char data[], unsigned int size, dc_dive_callback_t callback, void *userdata); suunto_solution_extract_dives (dc_device_t *device, const unsigned char data[], unsigned int size, dc_dive_callback_t callback, void *userdata);
dc_status_t dc_status_t
suunto_solution_device_open (dc_device_t **out, dc_context_t *context, const char *name) suunto_solution_device_open (dc_device_t **out, dc_context_t *context, dc_iostream_t *iostream)
{ {
dc_status_t status = DC_STATUS_SUCCESS; dc_status_t status = DC_STATUS_SUCCESS;
suunto_solution_device_t *device = NULL; suunto_solution_device_t *device = NULL;
@ -78,65 +76,39 @@ suunto_solution_device_open (dc_device_t **out, dc_context_t *context, const cha
} }
// Set the default values. // Set the default values.
device->iostream = NULL; device->iostream = iostream;
// Open the device.
status = dc_serial_open (&device->iostream, context, name);
if (status != DC_STATUS_SUCCESS) {
ERROR (context, "Failed to open the serial port.");
goto error_free;
}
// Set the serial communication protocol (1200 8N2). // Set the serial communication protocol (1200 8N2).
status = dc_iostream_configure (device->iostream, 1200, 8, DC_PARITY_NONE, DC_STOPBITS_TWO, DC_FLOWCONTROL_NONE); status = dc_iostream_configure (device->iostream, 1200, 8, DC_PARITY_NONE, DC_STOPBITS_TWO, DC_FLOWCONTROL_NONE);
if (status != DC_STATUS_SUCCESS) { if (status != DC_STATUS_SUCCESS) {
ERROR (context, "Failed to set the terminal attributes."); ERROR (context, "Failed to set the terminal attributes.");
goto error_close; goto error_free;
} }
// Set the timeout for receiving data (1000ms). // Set the timeout for receiving data (1000ms).
status = dc_iostream_set_timeout (device->iostream, 1000); status = dc_iostream_set_timeout (device->iostream, 1000);
if (status != DC_STATUS_SUCCESS) { if (status != DC_STATUS_SUCCESS) {
ERROR (context, "Failed to set the timeout."); ERROR (context, "Failed to set the timeout.");
goto error_close; goto error_free;
} }
// Clear the RTS line. // Clear the RTS line.
status = dc_iostream_set_rts (device->iostream, 0); status = dc_iostream_set_rts (device->iostream, 0);
if (status != DC_STATUS_SUCCESS) { if (status != DC_STATUS_SUCCESS) {
ERROR (context, "Failed to set the DTR/RTS line."); ERROR (context, "Failed to set the DTR/RTS line.");
goto error_close; goto error_free;
} }
*out = (dc_device_t*) device; *out = (dc_device_t*) device;
return DC_STATUS_SUCCESS; return DC_STATUS_SUCCESS;
error_close:
dc_iostream_close (device->iostream);
error_free: error_free:
dc_device_deallocate ((dc_device_t *) device); dc_device_deallocate ((dc_device_t *) device);
return status; return status;
} }
static dc_status_t
suunto_solution_device_close (dc_device_t *abstract)
{
dc_status_t status = DC_STATUS_SUCCESS;
suunto_solution_device_t *device = (suunto_solution_device_t*) abstract;
dc_status_t rc = DC_STATUS_SUCCESS;
// Close the device.
rc = dc_iostream_close (device->iostream);
if (rc != DC_STATUS_SUCCESS) {
dc_status_set_error(&status, rc);
}
return status;
}
static dc_status_t static dc_status_t
suunto_solution_device_dump (dc_device_t *abstract, dc_buffer_t *buffer) suunto_solution_device_dump (dc_device_t *abstract, dc_buffer_t *buffer)
{ {

View File

@ -23,6 +23,7 @@
#define SUUNTO_SOLUTION_H #define SUUNTO_SOLUTION_H
#include <libdivecomputer/context.h> #include <libdivecomputer/context.h>
#include <libdivecomputer/iostream.h>
#include <libdivecomputer/device.h> #include <libdivecomputer/device.h>
#include <libdivecomputer/parser.h> #include <libdivecomputer/parser.h>
@ -31,7 +32,7 @@ extern "C" {
#endif /* __cplusplus */ #endif /* __cplusplus */
dc_status_t dc_status_t
suunto_solution_device_open (dc_device_t **device, dc_context_t *context, const char *name); suunto_solution_device_open (dc_device_t **device, dc_context_t *context, dc_iostream_t *iostream);
dc_status_t dc_status_t
suunto_solution_parser_create (dc_parser_t **parser, dc_context_t *context); suunto_solution_parser_create (dc_parser_t **parser, dc_context_t *context);

View File

@ -27,7 +27,6 @@
#include "suunto_common.h" #include "suunto_common.h"
#include "context-private.h" #include "context-private.h"
#include "device-private.h" #include "device-private.h"
#include "serial.h"
#include "checksum.h" #include "checksum.h"
#include "array.h" #include "array.h"
@ -53,7 +52,6 @@ static dc_status_t suunto_vyper_device_read (dc_device_t *abstract, unsigned int
static dc_status_t suunto_vyper_device_write (dc_device_t *abstract, unsigned int address, const unsigned char data[], unsigned int size); static dc_status_t suunto_vyper_device_write (dc_device_t *abstract, unsigned int address, const unsigned char data[], unsigned int size);
static dc_status_t suunto_vyper_device_dump (dc_device_t *abstract, dc_buffer_t *buffer); static dc_status_t suunto_vyper_device_dump (dc_device_t *abstract, dc_buffer_t *buffer);
static dc_status_t suunto_vyper_device_foreach (dc_device_t *abstract, dc_dive_callback_t callback, void *userdata); static dc_status_t suunto_vyper_device_foreach (dc_device_t *abstract, dc_dive_callback_t callback, void *userdata);
static dc_status_t suunto_vyper_device_close (dc_device_t *abstract);
static const dc_device_vtable_t suunto_vyper_device_vtable = { static const dc_device_vtable_t suunto_vyper_device_vtable = {
sizeof(suunto_vyper_device_t), sizeof(suunto_vyper_device_t),
@ -64,7 +62,7 @@ static const dc_device_vtable_t suunto_vyper_device_vtable = {
suunto_vyper_device_dump, /* dump */ suunto_vyper_device_dump, /* dump */
suunto_vyper_device_foreach, /* foreach */ suunto_vyper_device_foreach, /* foreach */
NULL, /* timesync */ NULL, /* timesync */
suunto_vyper_device_close /* close */ NULL /* close */
}; };
static const suunto_common_layout_t suunto_vyper_layout = { static const suunto_common_layout_t suunto_vyper_layout = {
@ -85,7 +83,7 @@ static const suunto_common_layout_t suunto_spyder_layout = {
dc_status_t dc_status_t
suunto_vyper_device_open (dc_device_t **out, dc_context_t *context, const char *name) suunto_vyper_device_open (dc_device_t **out, dc_context_t *context, dc_iostream_t *iostream)
{ {
dc_status_t status = DC_STATUS_SUCCESS; dc_status_t status = DC_STATUS_SUCCESS;
suunto_vyper_device_t *device = NULL; suunto_vyper_device_t *device = NULL;
@ -104,34 +102,27 @@ suunto_vyper_device_open (dc_device_t **out, dc_context_t *context, const char *
suunto_common_device_init (&device->base); suunto_common_device_init (&device->base);
// Set the default values. // Set the default values.
device->iostream = NULL; device->iostream = iostream;
// Open the device.
status = dc_serial_open (&device->iostream, context, name);
if (status != DC_STATUS_SUCCESS) {
ERROR (context, "Failed to open the serial port.");
goto error_free;
}
// Set the serial communication protocol (2400 8O1). // Set the serial communication protocol (2400 8O1).
status = dc_iostream_configure (device->iostream, 2400, 8, DC_PARITY_ODD, DC_STOPBITS_ONE, DC_FLOWCONTROL_NONE); status = dc_iostream_configure (device->iostream, 2400, 8, DC_PARITY_ODD, DC_STOPBITS_ONE, DC_FLOWCONTROL_NONE);
if (status != DC_STATUS_SUCCESS) { if (status != DC_STATUS_SUCCESS) {
ERROR (context, "Failed to set the terminal attributes."); ERROR (context, "Failed to set the terminal attributes.");
goto error_close; goto error_free;
} }
// Set the timeout for receiving data (1000 ms). // Set the timeout for receiving data (1000 ms).
status = dc_iostream_set_timeout (device->iostream, 1000); status = dc_iostream_set_timeout (device->iostream, 1000);
if (status != DC_STATUS_SUCCESS) { if (status != DC_STATUS_SUCCESS) {
ERROR (context, "Failed to set the timeout."); ERROR (context, "Failed to set the timeout.");
goto error_close; goto error_free;
} }
// Set the DTR line (power supply for the interface). // Set the DTR line (power supply for the interface).
status = dc_iostream_set_dtr (device->iostream, 1); status = dc_iostream_set_dtr (device->iostream, 1);
if (status != DC_STATUS_SUCCESS) { if (status != DC_STATUS_SUCCESS) {
ERROR (context, "Failed to set the DTR line."); ERROR (context, "Failed to set the DTR line.");
goto error_close; goto error_free;
} }
// Give the interface 100 ms to settle and draw power up. // Give the interface 100 ms to settle and draw power up.
@ -144,31 +135,12 @@ suunto_vyper_device_open (dc_device_t **out, dc_context_t *context, const char *
return DC_STATUS_SUCCESS; return DC_STATUS_SUCCESS;
error_close:
dc_iostream_close (device->iostream);
error_free: error_free:
dc_device_deallocate ((dc_device_t *) device); dc_device_deallocate ((dc_device_t *) device);
return status; return status;
} }
static dc_status_t
suunto_vyper_device_close (dc_device_t *abstract)
{
dc_status_t status = DC_STATUS_SUCCESS;
suunto_vyper_device_t *device = (suunto_vyper_device_t*) abstract;
dc_status_t rc = DC_STATUS_SUCCESS;
// Close the device.
rc = dc_iostream_close (device->iostream);
if (rc != DC_STATUS_SUCCESS) {
dc_status_set_error(&status, rc);
}
return status;
}
static dc_status_t static dc_status_t
suunto_vyper_send (suunto_vyper_device_t *device, const unsigned char command[], unsigned int csize) suunto_vyper_send (suunto_vyper_device_t *device, const unsigned char command[], unsigned int csize)
{ {

View File

@ -23,6 +23,7 @@
#define SUUNTO_VYPER_H #define SUUNTO_VYPER_H
#include <libdivecomputer/context.h> #include <libdivecomputer/context.h>
#include <libdivecomputer/iostream.h>
#include <libdivecomputer/device.h> #include <libdivecomputer/device.h>
#include <libdivecomputer/parser.h> #include <libdivecomputer/parser.h>
@ -31,7 +32,7 @@ extern "C" {
#endif /* __cplusplus */ #endif /* __cplusplus */
dc_status_t dc_status_t
suunto_vyper_device_open (dc_device_t **device, dc_context_t *context, const char *name); suunto_vyper_device_open (dc_device_t **device, dc_context_t *context, dc_iostream_t *iostream);
dc_status_t dc_status_t
suunto_vyper_parser_create (dc_parser_t **parser, dc_context_t *context); suunto_vyper_parser_create (dc_parser_t **parser, dc_context_t *context);

View File

@ -25,7 +25,6 @@
#include "suunto_vyper2.h" #include "suunto_vyper2.h"
#include "suunto_common2.h" #include "suunto_common2.h"
#include "context-private.h" #include "context-private.h"
#include "serial.h"
#include "checksum.h" #include "checksum.h"
#include "array.h" #include "array.h"
#include "timer.h" #include "timer.h"
@ -76,7 +75,7 @@ static const suunto_common2_layout_t suunto_helo2_layout = {
dc_status_t dc_status_t
suunto_vyper2_device_open (dc_device_t **out, dc_context_t *context, const char *name) suunto_vyper2_device_open (dc_device_t **out, dc_context_t *context, dc_iostream_t *iostream)
{ {
dc_status_t status = DC_STATUS_SUCCESS; dc_status_t status = DC_STATUS_SUCCESS;
suunto_vyper2_device_t *device = NULL; suunto_vyper2_device_t *device = NULL;
@ -95,7 +94,7 @@ suunto_vyper2_device_open (dc_device_t **out, dc_context_t *context, const char
suunto_common2_device_init (&device->base); suunto_common2_device_init (&device->base);
// Set the default values. // Set the default values.
device->iostream = NULL; device->iostream = iostream;
// Create a high resolution timer. // Create a high resolution timer.
status = dc_timer_new (&device->timer); status = dc_timer_new (&device->timer);
@ -104,32 +103,25 @@ suunto_vyper2_device_open (dc_device_t **out, dc_context_t *context, const char
goto error_free; goto error_free;
} }
// Open the device.
status = dc_serial_open (&device->iostream, context, name);
if (status != DC_STATUS_SUCCESS) {
ERROR (context, "Failed to open the serial port.");
goto error_timer_free;
}
// Set the serial communication protocol (9600 8N1). // Set the serial communication protocol (9600 8N1).
status = dc_iostream_configure (device->iostream, 9600, 8, DC_PARITY_NONE, DC_STOPBITS_ONE, DC_FLOWCONTROL_NONE); status = dc_iostream_configure (device->iostream, 9600, 8, DC_PARITY_NONE, DC_STOPBITS_ONE, DC_FLOWCONTROL_NONE);
if (status != DC_STATUS_SUCCESS) { if (status != DC_STATUS_SUCCESS) {
ERROR (context, "Failed to set the terminal attributes."); ERROR (context, "Failed to set the terminal attributes.");
goto error_close; goto error_timer_free;
} }
// Set the timeout for receiving data (3000 ms). // Set the timeout for receiving data (3000 ms).
status = dc_iostream_set_timeout (device->iostream, 3000); status = dc_iostream_set_timeout (device->iostream, 3000);
if (status != DC_STATUS_SUCCESS) { if (status != DC_STATUS_SUCCESS) {
ERROR (context, "Failed to set the timeout."); ERROR (context, "Failed to set the timeout.");
goto error_close; goto error_timer_free;
} }
// Set the DTR line (power supply for the interface). // Set the DTR line (power supply for the interface).
status = dc_iostream_set_dtr (device->iostream, 1); status = dc_iostream_set_dtr (device->iostream, 1);
if (status != DC_STATUS_SUCCESS) { if (status != DC_STATUS_SUCCESS) {
ERROR (context, "Failed to set the DTR line."); ERROR (context, "Failed to set the DTR line.");
goto error_close; goto error_timer_free;
} }
// Give the interface 100 ms to settle and draw power up. // Give the interface 100 ms to settle and draw power up.
@ -139,14 +131,14 @@ suunto_vyper2_device_open (dc_device_t **out, dc_context_t *context, const char
status = dc_iostream_purge (device->iostream, DC_DIRECTION_ALL); status = dc_iostream_purge (device->iostream, DC_DIRECTION_ALL);
if (status != DC_STATUS_SUCCESS) { if (status != DC_STATUS_SUCCESS) {
ERROR (context, "Failed to reset IO state."); ERROR (context, "Failed to reset IO state.");
goto error_close; goto error_timer_free;
} }
// Read the version info. // Read the version info.
status = suunto_common2_device_version ((dc_device_t *) device, device->base.version, sizeof (device->base.version)); status = suunto_common2_device_version ((dc_device_t *) device, device->base.version, sizeof (device->base.version));
if (status != DC_STATUS_SUCCESS) { if (status != DC_STATUS_SUCCESS) {
ERROR (context, "Failed to read the version info."); ERROR (context, "Failed to read the version info.");
goto error_close; goto error_timer_free;
} }
// Override the base class values. // Override the base class values.
@ -160,8 +152,6 @@ suunto_vyper2_device_open (dc_device_t **out, dc_context_t *context, const char
return DC_STATUS_SUCCESS; return DC_STATUS_SUCCESS;
error_close:
dc_iostream_close (device->iostream);
error_timer_free: error_timer_free:
dc_timer_free (device->timer); dc_timer_free (device->timer);
error_free: error_free:
@ -173,19 +163,11 @@ error_free:
static dc_status_t static dc_status_t
suunto_vyper2_device_close (dc_device_t *abstract) suunto_vyper2_device_close (dc_device_t *abstract)
{ {
dc_status_t status = DC_STATUS_SUCCESS;
suunto_vyper2_device_t *device = (suunto_vyper2_device_t*) abstract; suunto_vyper2_device_t *device = (suunto_vyper2_device_t*) abstract;
dc_status_t rc = DC_STATUS_SUCCESS;
dc_timer_free (device->timer); dc_timer_free (device->timer);
// Close the device. return DC_STATUS_SUCCESS;
rc = dc_iostream_close (device->iostream);
if (rc != DC_STATUS_SUCCESS) {
dc_status_set_error(&status, rc);
}
return status;
} }

View File

@ -27,11 +27,12 @@ extern "C" {
#endif /* __cplusplus */ #endif /* __cplusplus */
#include <libdivecomputer/context.h> #include <libdivecomputer/context.h>
#include <libdivecomputer/iostream.h>
#include <libdivecomputer/device.h> #include <libdivecomputer/device.h>
#include <libdivecomputer/suunto_vyper2.h> #include <libdivecomputer/suunto_vyper2.h>
dc_status_t dc_status_t
suunto_vyper2_device_open (dc_device_t **device, dc_context_t *context, const char *name); suunto_vyper2_device_open (dc_device_t **device, dc_context_t *context, dc_iostream_t *iostream);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -49,7 +49,7 @@
#include <hidapi/hidapi.h> #include <hidapi/hidapi.h>
#endif #endif
#include "usbhid.h" #include <libdivecomputer/usbhid.h>
#include "common-private.h" #include "common-private.h"
#include "context-private.h" #include "context-private.h"
@ -473,7 +473,7 @@ dc_usbhid_open (dc_iostream_t **out, dc_context_t *context, unsigned int vid, un
INFO (context, "Open: vid=%04x, pid=%04x", vid, pid); INFO (context, "Open: vid=%04x, pid=%04x", vid, pid);
// Allocate memory. // Allocate memory.
usbhid = (dc_usbhid_t *) dc_iostream_allocate (context, &dc_usbhid_vtable); usbhid = (dc_usbhid_t *) dc_iostream_allocate (context, &dc_usbhid_vtable, DC_TRANSPORT_USBHID);
if (usbhid == NULL) { if (usbhid == NULL) {
ERROR (context, "Out of memory."); ERROR (context, "Out of memory.");
return DC_STATUS_NOMEMORY; return DC_STATUS_NOMEMORY;

View File

@ -25,7 +25,6 @@
#include "uwatec_aladin.h" #include "uwatec_aladin.h"
#include "context-private.h" #include "context-private.h"
#include "device-private.h" #include "device-private.h"
#include "serial.h"
#include "ringbuffer.h" #include "ringbuffer.h"
#include "checksum.h" #include "checksum.h"
#include "array.h" #include "array.h"
@ -52,7 +51,6 @@ typedef struct uwatec_aladin_device_t {
static dc_status_t uwatec_aladin_device_set_fingerprint (dc_device_t *abstract, const unsigned char data[], unsigned int size); static dc_status_t uwatec_aladin_device_set_fingerprint (dc_device_t *abstract, const unsigned char data[], unsigned int size);
static dc_status_t uwatec_aladin_device_dump (dc_device_t *abstract, dc_buffer_t *buffer); static dc_status_t uwatec_aladin_device_dump (dc_device_t *abstract, dc_buffer_t *buffer);
static dc_status_t uwatec_aladin_device_foreach (dc_device_t *abstract, dc_dive_callback_t callback, void *userdata); static dc_status_t uwatec_aladin_device_foreach (dc_device_t *abstract, dc_dive_callback_t callback, void *userdata);
static dc_status_t uwatec_aladin_device_close (dc_device_t *abstract);
static const dc_device_vtable_t uwatec_aladin_device_vtable = { static const dc_device_vtable_t uwatec_aladin_device_vtable = {
sizeof(uwatec_aladin_device_t), sizeof(uwatec_aladin_device_t),
@ -63,14 +61,14 @@ static const dc_device_vtable_t uwatec_aladin_device_vtable = {
uwatec_aladin_device_dump, /* dump */ uwatec_aladin_device_dump, /* dump */
uwatec_aladin_device_foreach, /* foreach */ uwatec_aladin_device_foreach, /* foreach */
NULL, /* timesync */ NULL, /* timesync */
uwatec_aladin_device_close /* close */ NULL /* close */
}; };
static dc_status_t static dc_status_t
uwatec_aladin_extract_dives (dc_device_t *device, const unsigned char data[], unsigned int size, dc_dive_callback_t callback, void *userdata); uwatec_aladin_extract_dives (dc_device_t *device, const unsigned char data[], unsigned int size, dc_dive_callback_t callback, void *userdata);
dc_status_t dc_status_t
uwatec_aladin_device_open (dc_device_t **out, dc_context_t *context, const char *name) uwatec_aladin_device_open (dc_device_t **out, dc_context_t *context, dc_iostream_t *iostream)
{ {
dc_status_t status = DC_STATUS_SUCCESS; dc_status_t status = DC_STATUS_SUCCESS;
uwatec_aladin_device_t *device = NULL; uwatec_aladin_device_t *device = NULL;
@ -86,75 +84,49 @@ uwatec_aladin_device_open (dc_device_t **out, dc_context_t *context, const char
} }
// Set the default values. // Set the default values.
device->iostream = NULL; device->iostream = iostream;
device->timestamp = 0; device->timestamp = 0;
device->systime = (dc_ticks_t) -1; device->systime = (dc_ticks_t) -1;
device->devtime = 0; device->devtime = 0;
// Open the device.
status = dc_serial_open (&device->iostream, context, name);
if (status != DC_STATUS_SUCCESS) {
ERROR (context, "Failed to open the serial port.");
goto error_free;
}
// Set the serial communication protocol (19200 8N1). // Set the serial communication protocol (19200 8N1).
status = dc_iostream_configure (device->iostream, 19200, 8, DC_PARITY_NONE, DC_STOPBITS_ONE, DC_FLOWCONTROL_NONE); status = dc_iostream_configure (device->iostream, 19200, 8, DC_PARITY_NONE, DC_STOPBITS_ONE, DC_FLOWCONTROL_NONE);
if (status != DC_STATUS_SUCCESS) { if (status != DC_STATUS_SUCCESS) {
ERROR (context, "Failed to set the terminal attributes."); ERROR (context, "Failed to set the terminal attributes.");
goto error_close; goto error_free;
} }
// Set the timeout for receiving data (INFINITE). // Set the timeout for receiving data (INFINITE).
status = dc_iostream_set_timeout (device->iostream, -1); status = dc_iostream_set_timeout (device->iostream, -1);
if (status != DC_STATUS_SUCCESS) { if (status != DC_STATUS_SUCCESS) {
ERROR (context, "Failed to set the timeout."); ERROR (context, "Failed to set the timeout.");
goto error_close; goto error_free;
} }
// Set the DTR line. // Set the DTR line.
status = dc_iostream_set_dtr (device->iostream, 1); status = dc_iostream_set_dtr (device->iostream, 1);
if (status != DC_STATUS_SUCCESS) { if (status != DC_STATUS_SUCCESS) {
ERROR (context, "Failed to set the DTR line."); ERROR (context, "Failed to set the DTR line.");
goto error_close; goto error_free;
} }
// Clear the RTS line. // Clear the RTS line.
status = dc_iostream_set_rts (device->iostream, 0); status = dc_iostream_set_rts (device->iostream, 0);
if (status != DC_STATUS_SUCCESS) { if (status != DC_STATUS_SUCCESS) {
ERROR (context, "Failed to clear the RTS line."); ERROR (context, "Failed to clear the RTS line.");
goto error_close; goto error_free;
} }
*out = (dc_device_t*) device; *out = (dc_device_t*) device;
return DC_STATUS_SUCCESS; return DC_STATUS_SUCCESS;
error_close:
dc_iostream_close (device->iostream);
error_free: error_free:
dc_device_deallocate ((dc_device_t *) device); dc_device_deallocate ((dc_device_t *) device);
return status; return status;
} }
static dc_status_t
uwatec_aladin_device_close (dc_device_t *abstract)
{
dc_status_t status = DC_STATUS_SUCCESS;
uwatec_aladin_device_t *device = (uwatec_aladin_device_t*) abstract;
dc_status_t rc = DC_STATUS_SUCCESS;
// Close the device.
rc = dc_iostream_close (device->iostream);
if (rc != DC_STATUS_SUCCESS) {
dc_status_set_error(&status, rc);
}
return status;
}
static dc_status_t static dc_status_t
uwatec_aladin_device_set_fingerprint (dc_device_t *abstract, const unsigned char data[], unsigned int size) uwatec_aladin_device_set_fingerprint (dc_device_t *abstract, const unsigned char data[], unsigned int size)
{ {

View File

@ -27,10 +27,11 @@ extern "C" {
#endif /* __cplusplus */ #endif /* __cplusplus */
#include <libdivecomputer/context.h> #include <libdivecomputer/context.h>
#include <libdivecomputer/iostream.h>
#include <libdivecomputer/device.h> #include <libdivecomputer/device.h>
dc_status_t dc_status_t
uwatec_aladin_device_open (dc_device_t **device, dc_context_t *context, const char *name); uwatec_aladin_device_open (dc_device_t **device, dc_context_t *context, dc_iostream_t *iostream);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -26,7 +26,6 @@
#include "uwatec_g2.h" #include "uwatec_g2.h"
#include "context-private.h" #include "context-private.h"
#include "device-private.h" #include "device-private.h"
#include "usbhid.h"
#include "array.h" #include "array.h"
#include "platform.h" #include "platform.h"
@ -48,7 +47,6 @@ typedef struct uwatec_g2_device_t {
static dc_status_t uwatec_g2_device_set_fingerprint (dc_device_t *device, const unsigned char data[], unsigned int size); static dc_status_t uwatec_g2_device_set_fingerprint (dc_device_t *device, const unsigned char data[], unsigned int size);
static dc_status_t uwatec_g2_device_dump (dc_device_t *abstract, dc_buffer_t *buffer); static dc_status_t uwatec_g2_device_dump (dc_device_t *abstract, dc_buffer_t *buffer);
static dc_status_t uwatec_g2_device_foreach (dc_device_t *abstract, dc_dive_callback_t callback, void *userdata); static dc_status_t uwatec_g2_device_foreach (dc_device_t *abstract, dc_dive_callback_t callback, void *userdata);
static dc_status_t uwatec_g2_device_close (dc_device_t *abstract);
static const dc_device_vtable_t uwatec_g2_device_vtable = { static const dc_device_vtable_t uwatec_g2_device_vtable = {
sizeof(uwatec_g2_device_t), sizeof(uwatec_g2_device_t),
@ -59,7 +57,7 @@ static const dc_device_vtable_t uwatec_g2_device_vtable = {
uwatec_g2_device_dump, /* dump */ uwatec_g2_device_dump, /* dump */
uwatec_g2_device_foreach, /* foreach */ uwatec_g2_device_foreach, /* foreach */
NULL, /* timesync */ NULL, /* timesync */
uwatec_g2_device_close /* close */ NULL /* close */
}; };
static dc_status_t static dc_status_t
@ -180,7 +178,7 @@ uwatec_g2_handshake (uwatec_g2_device_t *device)
dc_status_t dc_status_t
uwatec_g2_device_open (dc_device_t **out, dc_context_t *context, unsigned int model) uwatec_g2_device_open (dc_device_t **out, dc_context_t *context, dc_iostream_t *iostream, unsigned int model)
{ {
dc_status_t status = DC_STATUS_SUCCESS; dc_status_t status = DC_STATUS_SUCCESS;
uwatec_g2_device_t *device = NULL; uwatec_g2_device_t *device = NULL;
@ -196,62 +194,28 @@ uwatec_g2_device_open (dc_device_t **out, dc_context_t *context, unsigned int mo
} }
// Set the default values. // Set the default values.
device->iostream = NULL; device->iostream = iostream;
device->timestamp = 0; device->timestamp = 0;
device->systime = (dc_ticks_t) -1; device->systime = (dc_ticks_t) -1;
device->devtime = 0; device->devtime = 0;
// Open the irda socket.
unsigned int vid = 0, pid = 0;
if (model == ALADINSQUARE) {
vid = 0xc251;
pid = 0x2006;
} else {
vid = 0x2e6c;
pid = 0x3201;
}
status = dc_usbhid_open (&device->iostream, context, vid, pid);
if (status != DC_STATUS_SUCCESS) {
ERROR (context, "Failed to open USB device");
goto error_free;
}
// Perform the handshaking. // Perform the handshaking.
status = uwatec_g2_handshake (device); status = uwatec_g2_handshake (device);
if (status != DC_STATUS_SUCCESS) { if (status != DC_STATUS_SUCCESS) {
ERROR (context, "Failed to handshake with the device."); ERROR (context, "Failed to handshake with the device.");
goto error_close; goto error_free;
} }
*out = (dc_device_t*) device; *out = (dc_device_t*) device;
return DC_STATUS_SUCCESS; return DC_STATUS_SUCCESS;
error_close:
dc_iostream_close (device->iostream);
error_free: error_free:
dc_device_deallocate ((dc_device_t *) device); dc_device_deallocate ((dc_device_t *) device);
return status; return status;
} }
static dc_status_t
uwatec_g2_device_close (dc_device_t *abstract)
{
dc_status_t status = DC_STATUS_SUCCESS;
uwatec_g2_device_t *device = (uwatec_g2_device_t*) abstract;
dc_status_t rc = DC_STATUS_SUCCESS;
// Close the device.
rc = dc_iostream_close (device->iostream);
if (status != DC_STATUS_SUCCESS) {
dc_status_set_error(&status, rc);
}
return status;
}
static dc_status_t static dc_status_t
uwatec_g2_device_set_fingerprint (dc_device_t *abstract, const unsigned char data[], unsigned int size) uwatec_g2_device_set_fingerprint (dc_device_t *abstract, const unsigned char data[], unsigned int size)
{ {

View File

@ -23,6 +23,7 @@
#define UWATEC_G2_H #define UWATEC_G2_H
#include <libdivecomputer/context.h> #include <libdivecomputer/context.h>
#include <libdivecomputer/iostream.h>
#include <libdivecomputer/device.h> #include <libdivecomputer/device.h>
#include <libdivecomputer/parser.h> #include <libdivecomputer/parser.h>
@ -31,7 +32,7 @@ extern "C" {
#endif /* __cplusplus */ #endif /* __cplusplus */
dc_status_t dc_status_t
uwatec_g2_device_open (dc_device_t **device, dc_context_t *context, unsigned int model); uwatec_g2_device_open (dc_device_t **device, dc_context_t *context, dc_iostream_t *iostream, unsigned int model);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -26,7 +26,6 @@
#include "uwatec_memomouse.h" #include "uwatec_memomouse.h"
#include "context-private.h" #include "context-private.h"
#include "device-private.h" #include "device-private.h"
#include "serial.h"
#include "checksum.h" #include "checksum.h"
#include "array.h" #include "array.h"
@ -48,7 +47,6 @@ typedef struct uwatec_memomouse_device_t {
static dc_status_t uwatec_memomouse_device_set_fingerprint (dc_device_t *device, const unsigned char data[], unsigned int size); static dc_status_t uwatec_memomouse_device_set_fingerprint (dc_device_t *device, const unsigned char data[], unsigned int size);
static dc_status_t uwatec_memomouse_device_dump (dc_device_t *abstract, dc_buffer_t *buffer); static dc_status_t uwatec_memomouse_device_dump (dc_device_t *abstract, dc_buffer_t *buffer);
static dc_status_t uwatec_memomouse_device_foreach (dc_device_t *abstract, dc_dive_callback_t callback, void *userdata); static dc_status_t uwatec_memomouse_device_foreach (dc_device_t *abstract, dc_dive_callback_t callback, void *userdata);
static dc_status_t uwatec_memomouse_device_close (dc_device_t *abstract);
static const dc_device_vtable_t uwatec_memomouse_device_vtable = { static const dc_device_vtable_t uwatec_memomouse_device_vtable = {
sizeof(uwatec_memomouse_device_t), sizeof(uwatec_memomouse_device_t),
@ -59,14 +57,14 @@ static const dc_device_vtable_t uwatec_memomouse_device_vtable = {
uwatec_memomouse_device_dump, /* dump */ uwatec_memomouse_device_dump, /* dump */
uwatec_memomouse_device_foreach, /* foreach */ uwatec_memomouse_device_foreach, /* foreach */
NULL, /* timesync */ NULL, /* timesync */
uwatec_memomouse_device_close /* close */ NULL /* close */
}; };
static dc_status_t static dc_status_t
uwatec_memomouse_extract_dives (dc_device_t *device, const unsigned char data[], unsigned int size, dc_dive_callback_t callback, void *userdata); uwatec_memomouse_extract_dives (dc_device_t *device, const unsigned char data[], unsigned int size, dc_dive_callback_t callback, void *userdata);
dc_status_t dc_status_t
uwatec_memomouse_device_open (dc_device_t **out, dc_context_t *context, const char *name) uwatec_memomouse_device_open (dc_device_t **out, dc_context_t *context, dc_iostream_t *iostream)
{ {
dc_status_t status = DC_STATUS_SUCCESS; dc_status_t status = DC_STATUS_SUCCESS;
uwatec_memomouse_device_t *device = NULL; uwatec_memomouse_device_t *device = NULL;
@ -82,44 +80,37 @@ uwatec_memomouse_device_open (dc_device_t **out, dc_context_t *context, const ch
} }
// Set the default values. // Set the default values.
device->iostream = NULL; device->iostream = iostream;
device->timestamp = 0; device->timestamp = 0;
device->systime = (dc_ticks_t) -1; device->systime = (dc_ticks_t) -1;
device->devtime = 0; device->devtime = 0;
// Open the device.
status = dc_serial_open (&device->iostream, context, name);
if (status != DC_STATUS_SUCCESS) {
ERROR (context, "Failed to open the serial port.");
goto error_free;
}
// Set the serial communication protocol (9600 8N1). // Set the serial communication protocol (9600 8N1).
status = dc_iostream_configure (device->iostream, 9600, 8, DC_PARITY_NONE, DC_STOPBITS_ONE, DC_FLOWCONTROL_NONE); status = dc_iostream_configure (device->iostream, 9600, 8, DC_PARITY_NONE, DC_STOPBITS_ONE, DC_FLOWCONTROL_NONE);
if (status != DC_STATUS_SUCCESS) { if (status != DC_STATUS_SUCCESS) {
ERROR (context, "Failed to set the terminal attributes."); ERROR (context, "Failed to set the terminal attributes.");
goto error_close; goto error_free;
} }
// Set the timeout for receiving data (1000 ms). // Set the timeout for receiving data (1000 ms).
status = dc_iostream_set_timeout (device->iostream, 1000); status = dc_iostream_set_timeout (device->iostream, 1000);
if (status != DC_STATUS_SUCCESS) { if (status != DC_STATUS_SUCCESS) {
ERROR (context, "Failed to set the timeout."); ERROR (context, "Failed to set the timeout.");
goto error_close; goto error_free;
} }
// Clear the DTR line. // Clear the DTR line.
status = dc_iostream_set_dtr (device->iostream, 0); status = dc_iostream_set_dtr (device->iostream, 0);
if (status != DC_STATUS_SUCCESS) { if (status != DC_STATUS_SUCCESS) {
ERROR (context, "Failed to clear the DTR line."); ERROR (context, "Failed to clear the DTR line.");
goto error_close; goto error_free;
} }
// Clear the RTS line. // Clear the RTS line.
status = dc_iostream_set_rts (device->iostream, 0); status = dc_iostream_set_rts (device->iostream, 0);
if (status != DC_STATUS_SUCCESS) { if (status != DC_STATUS_SUCCESS) {
ERROR (context, "Failed to clear the RTS line."); ERROR (context, "Failed to clear the RTS line.");
goto error_close; goto error_free;
} }
// Make sure everything is in a sane state. // Make sure everything is in a sane state.
@ -129,31 +120,12 @@ uwatec_memomouse_device_open (dc_device_t **out, dc_context_t *context, const ch
return DC_STATUS_SUCCESS; return DC_STATUS_SUCCESS;
error_close:
dc_iostream_close (device->iostream);
error_free: error_free:
dc_device_deallocate ((dc_device_t *) device); dc_device_deallocate ((dc_device_t *) device);
return status; return status;
} }
static dc_status_t
uwatec_memomouse_device_close (dc_device_t *abstract)
{
dc_status_t status = DC_STATUS_SUCCESS;
uwatec_memomouse_device_t *device = (uwatec_memomouse_device_t*) abstract;
dc_status_t rc = DC_STATUS_SUCCESS;
// Close the device.
rc = dc_iostream_close (device->iostream);
if (rc != DC_STATUS_SUCCESS) {
dc_status_set_error(&status, rc);
}
return status;
}
static dc_status_t static dc_status_t
uwatec_memomouse_device_set_fingerprint (dc_device_t *abstract, const unsigned char data[], unsigned int size) uwatec_memomouse_device_set_fingerprint (dc_device_t *abstract, const unsigned char data[], unsigned int size)
{ {

Some files were not shown because too many files have changed in this diff Show More