diff --git a/examples/Makefile.am b/examples/Makefile.am index 6b70f99..3cc556e 100644 --- a/examples/Makefile.am +++ b/examples/Makefile.am @@ -12,6 +12,7 @@ dctool_SOURCES = \ dctool_help.c \ dctool_version.c \ dctool_list.c \ + dctool_scan.c \ dctool_download.c \ dctool_dump.c \ dctool_parse.c \ diff --git a/examples/common.c b/examples/common.c index 1024fde..f6ecceb 100644 --- a/examples/common.c +++ b/examples/common.c @@ -19,6 +19,7 @@ * MA 02110-1301 USA */ +#include #include #include @@ -27,6 +28,11 @@ #include #endif +#include +#include +#include +#include + #include "common.h" #include "utils.h" @@ -44,6 +50,11 @@ typedef struct backend_table_t { unsigned int model; } 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[] = { {"solution", DC_FAMILY_SUUNTO_SOLUTION, 0}, {"eon", DC_FAMILY_SUUNTO_EON, 0}, @@ -81,6 +92,14 @@ static const backend_table_t g_backends[] = { {"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 * dctool_errmsg (dc_status_t status) { @@ -145,6 +164,41 @@ dctool_family_model (dc_family_t type) 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 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; } + +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; + } +} diff --git a/examples/common.h b/examples/common.h index edb7872..4ae5b9c 100644 --- a/examples/common.h +++ b/examples/common.h @@ -24,6 +24,7 @@ #include #include +#include #include #ifdef __cplusplus @@ -42,6 +43,15 @@ dctool_family_name (dc_family_t type); unsigned int 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 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 * 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 } #endif /* __cplusplus */ diff --git a/examples/dctool.c b/examples/dctool.c index 52eb67b..ddcd596 100644 --- a/examples/dctool.c +++ b/examples/dctool.c @@ -58,6 +58,7 @@ static const dctool_command_t *g_commands[] = { &dctool_help, &dctool_version, &dctool_list, + &dctool_scan, &dctool_download, &dctool_dump, &dctool_parse, diff --git a/examples/dctool.h b/examples/dctool.h index 06e58a8..a79cf75 100644 --- a/examples/dctool.h +++ b/examples/dctool.h @@ -45,6 +45,7 @@ typedef struct dctool_command_t { extern const dctool_command_t dctool_help; extern const dctool_command_t dctool_version; 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_dump; extern const dctool_command_t dctool_parse; diff --git a/examples/dctool_download.c b/examples/dctool_download.c index 2c8f43d..2a39f5f 100644 --- a/examples/dctool_download.c +++ b/examples/dctool_download.c @@ -152,18 +152,28 @@ event_cb (dc_device_t *device, dc_event_type_t event, const void *data, void *us } 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_iostream_t *iostream = NULL; dc_device_t *device = NULL; dc_buffer_t *ofingerprint = NULL; - // Open the device. - message ("Opening the device (%s %s, %s).\n", - dc_descriptor_get_vendor (descriptor), - dc_descriptor_get_product (descriptor), + // Open the I/O stream. + message ("Opening the I/O stream (%s, %s).\n", + dctool_transport_name (transport), 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) { ERROR ("Error opening the device."); goto cleanup; @@ -236,6 +246,7 @@ download (dc_context_t *context, dc_descriptor_t *descriptor, const char *devnam cleanup: dc_buffer_free (ofingerprint); dc_device_close (device); + dc_iostream_close (iostream); return rc; } @@ -247,6 +258,7 @@ dctool_download_run (int argc, char *argv[], dc_context_t *context, dc_descripto dc_buffer_t *fingerprint = NULL; dctool_output_t *output = NULL; dctool_units_t units = DCTOOL_UNITS_METRIC; + dc_transport_t transport = dctool_transport_default (descriptor); // Default option values. 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. int opt = 0; - const char *optstring = "ho:p:c:f:u:"; + const char *optstring = "ht:o:p:c:f:u:"; #ifdef HAVE_GETOPT_LONG struct option options[] = { {"help", no_argument, 0, 'h'}, + {"transport", required_argument, 0, 't'}, {"output", required_argument, 0, 'o'}, {"fingerprint", required_argument, 0, 'p'}, {"cache", required_argument, 0, 'c'}, @@ -276,6 +289,9 @@ dctool_download_run (int argc, char *argv[], dc_context_t *context, dc_descripto case 'h': help = 1; break; + case 't': + transport = dctool_transport_type (optarg); + break; case 'o': filename = optarg; break; @@ -308,6 +324,13 @@ dctool_download_run (int argc, char *argv[], dc_context_t *context, dc_descripto 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. 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. - status = download (context, descriptor, argv[0], cachedir, fingerprint, output); + status = download (context, descriptor, transport, argv[0], cachedir, fingerprint, output); if (status != DC_STATUS_SUCCESS) { message ("ERROR: %s\n", dctool_errmsg (status)); exitcode = EXIT_FAILURE; @@ -352,6 +375,7 @@ const dctool_command_t dctool_download = { "Options:\n" #ifdef HAVE_GETOPT_LONG " -h, --help Show help message\n" + " -t, --transport Transport type\n" " -o, --output Output filename\n" " -p, --fingerprint Fingerprint data (hexadecimal)\n" " -c, --cache Cache directory\n" @@ -359,6 +383,7 @@ const dctool_command_t dctool_download = { " -u, --units Set units (metric or imperial)\n" #else " -h Show help message\n" + " -t Transport type\n" " -o Output filename\n" " -p Fingerprint data (hexadecimal)\n" " -c Cache directory\n" diff --git a/examples/dctool_dump.c b/examples/dctool_dump.c index ce59899..6aa2e4a 100644 --- a/examples/dctool_dump.c +++ b/examples/dctool_dump.c @@ -40,17 +40,27 @@ #include "utils.h" 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_iostream_t *iostream = NULL; dc_device_t *device = NULL; - // Open the device. - message ("Opening the device (%s %s, %s).\n", - dc_descriptor_get_vendor (descriptor), - dc_descriptor_get_product (descriptor), + // Open the I/O stream. + message ("Opening the I/O stream (%s, %s).\n", + dctool_transport_name (transport), 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) { ERROR ("Error opening the device."); goto cleanup; @@ -93,6 +103,7 @@ dump (dc_context_t *context, dc_descriptor_t *descriptor, const char *devname, d cleanup: dc_device_close (device); + dc_iostream_close (iostream); 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_buffer_t *fingerprint = NULL; dc_buffer_t *buffer = NULL; + dc_transport_t transport = dctool_transport_default (descriptor); // Default option values. 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. int opt = 0; - const char *optstring = "ho:p:"; + const char *optstring = "ht:o:p:"; #ifdef HAVE_GETOPT_LONG struct option options[] = { {"help", no_argument, 0, 'h'}, + {"transport", required_argument, 0, 't'}, {"output", required_argument, 0, 'o'}, {"fingerprint", required_argument, 0, 'p'}, {0, 0, 0, 0 } @@ -127,6 +140,9 @@ dctool_dump_run (int argc, char *argv[], dc_context_t *context, dc_descriptor_t case 'h': help = 1; break; + case 't': + transport = dctool_transport_type (optarg); + break; case 'o': filename = optarg; break; @@ -147,6 +163,13 @@ dctool_dump_run (int argc, char *argv[], dc_context_t *context, dc_descriptor_t 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. 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); // 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) { message ("ERROR: %s\n", dctool_errmsg (status)); exitcode = EXIT_FAILURE; @@ -181,10 +204,12 @@ const dctool_command_t dctool_dump = { "Options:\n" #ifdef HAVE_GETOPT_LONG " -h, --help Show help message\n" + " -t, --transport Transport type\n" " -o, --output Output filename\n" " -p, --fingerprint Fingerprint data (hexadecimal)\n" #else " -h Show help message\n" + " -t Transport type\n" " -o Output filename\n" " -p Fingerprint data (hexadecimal)\n" #endif diff --git a/examples/dctool_fwupdate.c b/examples/dctool_fwupdate.c index 13b4fe3..e5daf35 100644 --- a/examples/dctool_fwupdate.c +++ b/examples/dctool_fwupdate.c @@ -41,17 +41,27 @@ #include "utils.h" 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_iostream_t *iostream = NULL; dc_device_t *device = NULL; - // Open the device. - message ("Opening the device (%s %s, %s).\n", - dc_descriptor_get_vendor (descriptor), - dc_descriptor_get_product (descriptor), + // Open the I/O stream. + message ("Opening the I/O stream (%s, %s).\n", + dctool_transport_name (transport), 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) { ERROR ("Error opening the device."); goto cleanup; @@ -94,6 +104,7 @@ fwupdate (dc_context_t *context, dc_descriptor_t *descriptor, const char *devnam cleanup: dc_device_close (device); + dc_iostream_close (iostream); return rc; } @@ -102,6 +113,7 @@ dctool_fwupdate_run (int argc, char *argv[], dc_context_t *context, dc_descripto { int exitcode = EXIT_SUCCESS; dc_status_t status = DC_STATUS_SUCCESS; + dc_transport_t transport = dctool_transport_default (descriptor); // Default option values. 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. int opt = 0; - const char *optstring = "hf:"; + const char *optstring = "ht:f:"; #ifdef HAVE_GETOPT_LONG struct option options[] = { {"help", no_argument, 0, 'h'}, + {"transport", required_argument, 0, 't'}, {"firmware", required_argument, 0, 'f'}, {0, 0, 0, 0 } }; @@ -124,6 +137,9 @@ dctool_fwupdate_run (int argc, char *argv[], dc_context_t *context, dc_descripto case 'f': filename = optarg; break; + case 't': + transport = dctool_transport_type (optarg); + break; case 'h': help = 1; break; @@ -141,6 +157,13 @@ dctool_fwupdate_run (int argc, char *argv[], dc_context_t *context, dc_descripto 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. if (!filename) { 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. - status = fwupdate (context, descriptor, argv[0], filename); + status = fwupdate (context, descriptor, transport, argv[0], filename); if (status != DC_STATUS_SUCCESS) { message ("ERROR: %s\n", dctool_errmsg (status)); exitcode = EXIT_FAILURE; @@ -171,9 +194,11 @@ const dctool_command_t dctool_fwupdate = { "Options:\n" #ifdef HAVE_GETOPT_LONG " -h, --help Show help message\n" + " -t, --transport Transport type\n" " -f, --firmware Firmware filename\n" #else " -h Show help message\n" + " -t Transport type\n" " -f Firmware filename\n" #endif }; diff --git a/examples/dctool_read.c b/examples/dctool_read.c index 85bd9de..2a9bf18 100644 --- a/examples/dctool_read.c +++ b/examples/dctool_read.c @@ -39,17 +39,27 @@ #include "utils.h" 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_iostream_t *iostream = NULL; dc_device_t *device = NULL; - // Open the device. - message ("Opening the device (%s %s, %s).\n", - dc_descriptor_get_vendor (descriptor), - dc_descriptor_get_product (descriptor), + // Open the I/O stream. + message ("Opening the I/O stream (%s, %s).\n", + dctool_transport_name (transport), 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) { ERROR ("Error opening the device."); goto cleanup; @@ -82,6 +92,7 @@ doread (dc_context_t *context, dc_descriptor_t *descriptor, const char *devname, cleanup: dc_device_close (device); + dc_iostream_close (iostream); return rc; } @@ -91,6 +102,7 @@ dctool_read_run (int argc, char *argv[], dc_context_t *context, dc_descriptor_t int exitcode = EXIT_SUCCESS; dc_status_t status = DC_STATUS_SUCCESS; dc_buffer_t *buffer = NULL; + dc_transport_t transport = dctool_transport_default (descriptor); // Default option values. 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. int opt = 0; - const char *optstring = "ha:c:o:"; + const char *optstring = "ht:a:c:o:"; #ifdef HAVE_GETOPT_LONG struct option options[] = { {"help", no_argument, 0, 'h'}, + {"transport", required_argument, 0, 't'}, {"address", required_argument, 0, 'a'}, {"count", required_argument, 0, 'c'}, {"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': help = 1; break; + case 't': + transport = dctool_transport_type (optarg); + break; case 'a': address = strtoul (optarg, NULL, 0); have_address = 1; @@ -142,6 +158,13 @@ dctool_read_run (int argc, char *argv[], dc_context_t *context, dc_descriptor_t 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. if (!have_address || !have_count) { 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. - status = doread (context, descriptor, argv[0], address, buffer); + status = doread (context, descriptor, transport, argv[0], address, buffer); if (status != DC_STATUS_SUCCESS) { message ("ERROR: %s\n", dctool_errmsg (status)); exitcode = EXIT_FAILURE; @@ -185,11 +208,13 @@ const dctool_command_t dctool_read = { "Options:\n" #ifdef HAVE_GETOPT_LONG " -h, --help Show help message\n" + " -t, --transport Transport type\n" " -a, --address
Memory address\n" " -c, --count Number of bytes\n" " -o, --output Output filename\n" #else " -h Show help message\n" + " -t Transport type\n" " -a
Memory address\n" " -c Number of bytes\n" " -o Output filename\n" diff --git a/examples/dctool_scan.c b/examples/dctool_scan.c new file mode 100644 index 0000000..b96d014 --- /dev/null +++ b/examples/dctool_scan.c @@ -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 +#include +#include +#ifdef HAVE_GETOPT_H +#include +#endif + +#include +#include +#include +#include +#include +#include +#include + +#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 Transport type\n" +#else + " -h Show help message\n" + " -t Transport type\n" +#endif +}; diff --git a/examples/dctool_timesync.c b/examples/dctool_timesync.c index 3a59af5..e0aff1f 100644 --- a/examples/dctool_timesync.c +++ b/examples/dctool_timesync.c @@ -39,17 +39,27 @@ #include "utils.h" 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_iostream_t *iostream = NULL; dc_device_t *device = NULL; - // Open the device. - message ("Opening the device (%s %s, %s).\n", - dc_descriptor_get_vendor (descriptor), - dc_descriptor_get_product (descriptor), + // Open the I/O stream. + message ("Opening the I/O stream (%s, %s).\n", + dctool_transport_name (transport), 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) { ERROR ("Error opening the device."); goto cleanup; @@ -82,6 +92,7 @@ do_timesync (dc_context_t *context, dc_descriptor_t *descriptor, const char *dev cleanup: dc_device_close (device); + dc_iostream_close (iostream); return rc; } @@ -90,16 +101,18 @@ dctool_timesync_run (int argc, char *argv[], dc_context_t *context, dc_descripto { int exitcode = EXIT_SUCCESS; dc_status_t status = DC_STATUS_SUCCESS; + dc_transport_t transport = dctool_transport_default (descriptor); // Default option values. unsigned int help = 0; // Parse the command-line options. int opt = 0; - const char *optstring = "h"; + 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) { @@ -124,6 +137,13 @@ dctool_timesync_run (int argc, char *argv[], dc_context_t *context, dc_descripto 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. dc_datetime_t datetime = {0}; 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. - status = do_timesync (context, descriptor, argv[0], &datetime); + status = do_timesync (context, descriptor, transport, argv[0], &datetime); if (status != DC_STATUS_SUCCESS) { message ("ERROR: %s\n", dctool_errmsg (status)); exitcode = EXIT_FAILURE; @@ -155,8 +175,10 @@ const dctool_command_t dctool_timesync = { "\n" "Options:\n" #ifdef HAVE_GETOPT_LONG - " -h, --help Show help message\n" + " -h, --help Show help message\n" + " -t, --transport Transport type\n" #else - " -h Show help message\n" + " -h Show help message\n" + " -t Transport type\n" #endif }; diff --git a/examples/dctool_write.c b/examples/dctool_write.c index 4bf193b..fc76c78 100644 --- a/examples/dctool_write.c +++ b/examples/dctool_write.c @@ -39,17 +39,27 @@ #include "utils.h" 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_iostream_t *iostream = NULL; dc_device_t *device = NULL; - // Open the device. - message ("Opening the device (%s %s, %s).\n", - dc_descriptor_get_vendor (descriptor), - dc_descriptor_get_product (descriptor), + // Open the I/O stream. + message ("Opening the I/O stream (%s, %s).\n", + dctool_transport_name (transport), 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) { ERROR ("Error opening the device."); goto cleanup; @@ -82,6 +92,7 @@ dowrite (dc_context_t *context, dc_descriptor_t *descriptor, const char *devname cleanup: dc_device_close (device); + dc_iostream_close (iostream); return rc; } @@ -91,6 +102,7 @@ dctool_write_run (int argc, char *argv[], dc_context_t *context, dc_descriptor_t int exitcode = EXIT_SUCCESS; dc_status_t status = DC_STATUS_SUCCESS; dc_buffer_t *buffer = NULL; + dc_transport_t transport = dctool_transport_default (descriptor); // Default option values. 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. int opt = 0; - const char *optstring = "ha:c:i:"; + const char *optstring = "ht:a:c:i:"; #ifdef HAVE_GETOPT_LONG struct option options[] = { {"help", no_argument, 0, 'h'}, + {"transport", required_argument, 0, 't'}, {"address", required_argument, 0, 'a'}, {"count", required_argument, 0, 'c'}, {"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': help = 1; break; + case 't': + transport = dctool_transport_type (optarg); + break; case 'a': address = strtoul (optarg, NULL, 0); have_address = 1; @@ -142,6 +158,13 @@ dctool_write_run (int argc, char *argv[], dc_context_t *context, dc_descriptor_t 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. if (!have_address) { 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. - status = dowrite (context, descriptor, argv[0], address, buffer); + status = dowrite (context, descriptor, transport, argv[0], address, buffer); if (status != DC_STATUS_SUCCESS) { message ("ERROR: %s\n", dctool_errmsg (status)); exitcode = EXIT_FAILURE; @@ -188,11 +211,13 @@ const dctool_command_t dctool_write = { "Options:\n" #ifdef HAVE_GETOPT_LONG " -h, --help Show help message\n" + " -t, --transport Transport type\n" " -a, --address
Memory address\n" " -c, --count Number of bytes\n" " -i, --input Input filename\n" #else " -h Show help message\n" + " -t Transport type\n" " -a
Memory address\n" " -c Number of bytes\n" " -i Input filename\n" diff --git a/include/libdivecomputer/Makefile.am b/include/libdivecomputer/Makefile.am index bbe7971..8e12f2d 100644 --- a/include/libdivecomputer/Makefile.am +++ b/include/libdivecomputer/Makefile.am @@ -7,6 +7,11 @@ libdivecomputer_HEADERS = \ descriptor.h \ iterator.h \ iostream.h \ + serial.h \ + bluetooth.h \ + irda.h \ + usbhid.h \ + custom.h \ device.h \ parser.h \ datetime.h \ diff --git a/src/bluetooth.h b/include/libdivecomputer/bluetooth.h similarity index 95% rename from src/bluetooth.h rename to include/libdivecomputer/bluetooth.h index 5b443a4..c0370ff 100644 --- a/src/bluetooth.h +++ b/include/libdivecomputer/bluetooth.h @@ -22,11 +22,11 @@ #ifndef DC_BLUETOOTH_H #define DC_BLUETOOTH_H -#include -#include -#include -#include -#include +#include "common.h" +#include "context.h" +#include "iostream.h" +#include "iterator.h" +#include "descriptor.h" #ifdef __cplusplus extern "C" { diff --git a/include/libdivecomputer/common.h b/include/libdivecomputer/common.h index 293de3b..0cbaa08 100644 --- a/include/libdivecomputer/common.h +++ b/include/libdivecomputer/common.h @@ -41,6 +41,15 @@ typedef enum dc_status_t { DC_STATUS_CANCELLED = -10 } 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 { DC_FAMILY_NULL = 0, /* Suunto */ diff --git a/include/libdivecomputer/context.h b/include/libdivecomputer/context.h index 861dbeb..824b67b 100644 --- a/include/libdivecomputer/context.h +++ b/include/libdivecomputer/context.h @@ -53,6 +53,9 @@ dc_context_set_loglevel (dc_context_t *context, dc_loglevel_t loglevel); dc_status_t 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 } #endif /* __cplusplus */ diff --git a/src/custom.h b/include/libdivecomputer/custom.h similarity index 93% rename from src/custom.h rename to include/libdivecomputer/custom.h index f1ab5da..4e3f9b0 100644 --- a/src/custom.h +++ b/include/libdivecomputer/custom.h @@ -22,9 +22,9 @@ #ifndef DC_CUSTOM_H #define DC_CUSTOM_H -#include -#include -#include +#include "common.h" +#include "context.h" +#include "iostream.h" #ifdef __cplusplus extern "C" { @@ -58,7 +58,7 @@ typedef struct dc_custom_cbs_t { * on failure. */ 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 } diff --git a/include/libdivecomputer/descriptor.h b/include/libdivecomputer/descriptor.h index a78b600..a2b4495 100644 --- a/include/libdivecomputer/descriptor.h +++ b/include/libdivecomputer/descriptor.h @@ -29,15 +29,6 @@ extern "C" { #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; dc_status_t @@ -58,8 +49,8 @@ dc_descriptor_get_type (dc_descriptor_t *descriptor); unsigned int dc_descriptor_get_model (dc_descriptor_t *descriptor); -dc_transport_t -dc_descriptor_get_transport (dc_descriptor_t *descriptor); +unsigned int +dc_descriptor_get_transports (dc_descriptor_t *descriptor); #ifdef __cplusplus } diff --git a/include/libdivecomputer/device.h b/include/libdivecomputer/device.h index f6d415c..8810a65 100644 --- a/include/libdivecomputer/device.h +++ b/include/libdivecomputer/device.h @@ -25,6 +25,7 @@ #include "common.h" #include "context.h" #include "descriptor.h" +#include "iostream.h" #include "buffer.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); 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_device_get_type (dc_device_t *device); diff --git a/include/libdivecomputer/iostream.h b/include/libdivecomputer/iostream.h index 832680d..e2cb439 100644 --- a/include/libdivecomputer/iostream.h +++ b/include/libdivecomputer/iostream.h @@ -82,6 +82,15 @@ typedef enum dc_line_t { DC_LINE_RNG = 0x08, /**< Ring indicator */ } 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. * diff --git a/src/irda.h b/include/libdivecomputer/irda.h similarity index 92% rename from src/irda.h rename to include/libdivecomputer/irda.h index 92e9557..f592ca9 100644 --- a/src/irda.h +++ b/include/libdivecomputer/irda.h @@ -22,11 +22,11 @@ #ifndef DC_IRDA_H #define DC_IRDA_H -#include -#include -#include -#include -#include +#include "common.h" +#include "context.h" +#include "iostream.h" +#include "iterator.h" +#include "descriptor.h" #ifdef __cplusplus extern "C" { diff --git a/src/serial.h b/include/libdivecomputer/serial.h similarity index 92% rename from src/serial.h rename to include/libdivecomputer/serial.h index 844c5b2..f1596b3 100644 --- a/src/serial.h +++ b/include/libdivecomputer/serial.h @@ -22,11 +22,11 @@ #ifndef DC_SERIAL_H #define DC_SERIAL_H -#include -#include -#include -#include -#include +#include "common.h" +#include "context.h" +#include "iostream.h" +#include "iterator.h" +#include "descriptor.h" #ifdef __cplusplus extern "C" { diff --git a/src/usbhid.h b/include/libdivecomputer/usbhid.h similarity index 93% rename from src/usbhid.h rename to include/libdivecomputer/usbhid.h index 16b302b..70823d1 100644 --- a/src/usbhid.h +++ b/include/libdivecomputer/usbhid.h @@ -22,11 +22,11 @@ #ifndef DC_USBHID_H #define DC_USBHID_H -#include -#include -#include -#include -#include +#include "common.h" +#include "context.h" +#include "iostream.h" +#include "iterator.h" +#include "descriptor.h" #ifdef __cplusplus extern "C" { diff --git a/msvc/libdivecomputer.vcproj b/msvc/libdivecomputer.vcproj index 1b1cd96..64e2966 100644 --- a/msvc/libdivecomputer.vcproj +++ b/msvc/libdivecomputer.vcproj @@ -549,7 +549,7 @@ > #include "common-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); // 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) { SYSERROR (context, S_ENOMEM); return DC_STATUS_NOMEMORY; diff --git a/src/citizen_aqualand.c b/src/citizen_aqualand.c index 99e60e6..63760ac 100644 --- a/src/citizen_aqualand.c +++ b/src/citizen_aqualand.c @@ -25,7 +25,6 @@ #include "citizen_aqualand.h" #include "context-private.h" #include "device-private.h" -#include "serial.h" #include "checksum.h" #include "ringbuffer.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_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_close (dc_device_t *abstract); static const dc_device_vtable_t citizen_aqualand_device_vtable = { 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_foreach, /* foreach */ NULL, /* timesync */ - citizen_aqualand_device_close /* close */ + NULL /* close */ }; 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; 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. - device->iostream = NULL; + device->iostream = iostream; 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). status = dc_iostream_configure (device->iostream, 4800, 8, DC_PARITY_NONE, DC_STOPBITS_ONE, DC_FLOWCONTROL_NONE); if (status != DC_STATUS_SUCCESS) { ERROR (context, "Failed to set the terminal attributes."); - goto error_close; + goto error_free; } // Set the timeout for receiving data (1000ms). status = dc_iostream_set_timeout (device->iostream, 1000); if (status != DC_STATUS_SUCCESS) { ERROR (context, "Failed to set the timeout."); - goto error_close; + goto error_free; } // 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; -error_close: - dc_iostream_close (device->iostream); error_free: dc_device_deallocate ((dc_device_t *) device); 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 citizen_aqualand_device_set_fingerprint (dc_device_t *abstract, const unsigned char data[], unsigned int size) { diff --git a/src/citizen_aqualand.h b/src/citizen_aqualand.h index 6391660..ac47cb6 100644 --- a/src/citizen_aqualand.h +++ b/src/citizen_aqualand.h @@ -23,6 +23,7 @@ #define CITIZEN_AQUALAND_H #include +#include #include #include @@ -31,7 +32,7 @@ extern "C" { #endif /* __cplusplus */ 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 citizen_aqualand_parser_create (dc_parser_t **parser, dc_context_t *context); diff --git a/src/cochran_commander.c b/src/cochran_commander.c index bbf92c7..63a00ba 100644 --- a/src/cochran_commander.c +++ b/src/cochran_commander.c @@ -26,7 +26,6 @@ #include "cochran_commander.h" #include "context-private.h" #include "device-private.h" -#include "serial.h" #include "array.h" #include "ringbuffer.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_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_close (dc_device_t *device); static const dc_device_vtable_t cochran_commander_device_vtable = { 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_foreach, /* foreach */ NULL, /* timesync */ - cochran_commander_device_close /* close */ + NULL /* close */ }; // 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 -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; 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. - device->iostream = NULL; + device->iostream = iostream; 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); if (status != DC_STATUS_SUCCESS) { - goto error_close; + goto error_free; } // Read ID from the device status = cochran_commander_read_id (device, device->id, sizeof(device->id)); if (status != DC_STATUS_SUCCESS) { ERROR (context, "Device not responding."); - goto error_close; + goto error_free; } 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: ERROR (context, "Unknown model"); status = DC_STATUS_UNSUPPORTED; - goto error_close; + goto error_free; } *out = (dc_device_t *) device; return DC_STATUS_SUCCESS; -error_close: - dc_iostream_close (device->iostream); error_free: dc_device_deallocate ((dc_device_t *) device); 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 cochran_commander_device_set_fingerprint (dc_device_t *abstract, const unsigned char data[], unsigned int size) { diff --git a/src/cochran_commander.h b/src/cochran_commander.h index e475b5f..84a521e 100644 --- a/src/cochran_commander.h +++ b/src/cochran_commander.h @@ -23,6 +23,7 @@ #define COCHRAN_COMMANDER_H #include +#include #include #include @@ -31,7 +32,7 @@ extern "C" { #endif /* __cplusplus */ 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 cochran_commander_parser_create (dc_parser_t **parser, dc_context_t *context, unsigned int model); diff --git a/src/context.c b/src/context.c index 181fef1..8c73aca 100644 --- a/src/context.c +++ b/src/context.c @@ -19,6 +19,10 @@ * MA 02110-1301 USA */ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + #include #include #include @@ -313,3 +317,35 @@ dc_context_hexdump (dc_context_t *context, dc_loglevel_t loglevel, const char *f 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 */ + ; +} diff --git a/src/cressi_edy.c b/src/cressi_edy.c index 327b4aa..89c4b48 100644 --- a/src/cressi_edy.c +++ b/src/cressi_edy.c @@ -26,7 +26,6 @@ #include "cressi_edy.h" #include "context-private.h" #include "device-private.h" -#include "serial.h" #include "checksum.h" #include "array.h" #include "ringbuffer.h" @@ -218,7 +217,7 @@ cressi_edy_quit (cressi_edy_device_t *device) 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; 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. - device->iostream = NULL; + device->iostream = iostream; device->layout = NULL; device->model = 0; 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). status = dc_iostream_configure (device->iostream, 1200, 8, DC_PARITY_NONE, DC_STOPBITS_ONE, DC_FLOWCONTROL_NONE); if (status != DC_STATUS_SUCCESS) { ERROR (context, "Failed to set the terminal attributes."); - goto error_close; + goto error_free; } // Set the timeout for receiving data (1000 ms). status = dc_iostream_set_timeout (device->iostream, 1000); if (status != DC_STATUS_SUCCESS) { ERROR (context, "Failed to set the timeout."); - goto error_close; + goto error_free; } // Set the DTR line. status = dc_iostream_set_dtr (device->iostream, 1); if (status != DC_STATUS_SUCCESS) { ERROR (context, "Failed to set the DTR line."); - goto error_close; + goto error_free; } // Clear the RTS line. status = dc_iostream_set_rts (device->iostream, 0); if (status != DC_STATUS_SUCCESS) { ERROR (context, "Failed to clear the RTS line."); - goto error_close; + goto error_free; } // 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); if (status != DC_STATUS_SUCCESS) { ERROR (context, "Failed to set the terminal attributes."); - goto error_close; + goto error_free; } // 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; -error_close: - dc_iostream_close (device->iostream); error_free: dc_device_deallocate ((dc_device_t *) device); return status; @@ -325,12 +315,6 @@ cressi_edy_device_close (dc_device_t *abstract) 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; } diff --git a/src/cressi_edy.h b/src/cressi_edy.h index d89f02f..7aa5a34 100644 --- a/src/cressi_edy.h +++ b/src/cressi_edy.h @@ -23,6 +23,7 @@ #define CRESSI_EDY_H #include +#include #include #include @@ -31,7 +32,7 @@ extern "C" { #endif /* __cplusplus */ 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 cressi_edy_parser_create (dc_parser_t **parser, dc_context_t *context, unsigned int model); diff --git a/src/cressi_leonardo.c b/src/cressi_leonardo.c index e9d142b..5359f66 100644 --- a/src/cressi_leonardo.c +++ b/src/cressi_leonardo.c @@ -26,7 +26,6 @@ #include "cressi_leonardo.h" #include "context-private.h" #include "device-private.h" -#include "serial.h" #include "checksum.h" #include "array.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_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_close (dc_device_t *abstract); static const dc_device_vtable_t cressi_leonardo_device_vtable = { 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_foreach, /* foreach */ NULL, /* timesync */ - cressi_leonardo_device_close /* close */ + NULL /* close */ }; static dc_status_t @@ -164,7 +162,7 @@ cressi_leonardo_transfer (cressi_leonardo_device_t *device, const unsigned char } 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; 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. - device->iostream = NULL; + device->iostream = iostream; 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). status = dc_iostream_configure (device->iostream, 115200, 8, DC_PARITY_NONE, DC_STOPBITS_ONE, DC_FLOWCONTROL_NONE); if (status != DC_STATUS_SUCCESS) { ERROR (context, "Failed to set the terminal attributes."); - goto error_close; + goto error_free; } // Set the timeout for receiving data (1000 ms). status = dc_iostream_set_timeout (device->iostream, 1000); if (status != DC_STATUS_SUCCESS) { ERROR (context, "Failed to set the timeout."); - goto error_close; + goto error_free; } // Set the RTS line. status = dc_iostream_set_rts (device->iostream, 1); if (status != DC_STATUS_SUCCESS) { ERROR (context, "Failed to set the RTS line."); - goto error_close; + goto error_free; } // Set the DTR line. status = dc_iostream_set_dtr (device->iostream, 1); if (status != DC_STATUS_SUCCESS) { ERROR (context, "Failed to set the DTR line."); - goto error_close; + goto error_free; } 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); if (status != DC_STATUS_SUCCESS) { ERROR (context, "Failed to clear the DTR line."); - goto error_close; + goto error_free; } 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; -error_close: - dc_iostream_close (device->iostream); error_free: dc_device_deallocate ((dc_device_t *) device); 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 cressi_leonardo_device_set_fingerprint (dc_device_t *abstract, const unsigned char data[], unsigned int size) { diff --git a/src/cressi_leonardo.h b/src/cressi_leonardo.h index c17b41b..982bb01 100644 --- a/src/cressi_leonardo.h +++ b/src/cressi_leonardo.h @@ -23,6 +23,7 @@ #define CRESSI_LEONARDO_H #include +#include #include #include @@ -31,7 +32,7 @@ extern "C" { #endif /* __cplusplus */ 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 cressi_leonardo_parser_create (dc_parser_t **parser, dc_context_t *context, unsigned int model); diff --git a/src/custom.c b/src/custom.c index 519a39e..1e03aa7 100644 --- a/src/custom.c +++ b/src/custom.c @@ -21,7 +21,7 @@ #include // malloc, free -#include "custom.h" +#include #include "iostream-private.h" #include "common-private.h" @@ -69,17 +69,17 @@ static const dc_iostream_vtable_t dc_custom_vtable = { }; 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; if (out == NULL || callbacks == NULL) return DC_STATUS_INVALIDARGS; - INFO (context, "Open: custom"); + INFO (context, "Open: transport=%u", transport); // 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) { ERROR (context, "Failed to allocate memory."); return DC_STATUS_NOMEMORY; diff --git a/src/descriptor.c b/src/descriptor.c index 7a65e71..948a9f3 100644 --- a/src/descriptor.c +++ b/src/descriptor.c @@ -19,26 +19,6 @@ * 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 #include #include @@ -61,6 +41,7 @@ struct dc_descriptor_t { const char *product; dc_family_t type; unsigned int model; + unsigned int transports; 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[] = { /* 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", DC_FAMILY_SUUNTO_EON, 0, NULL}, - {"Suunto", "Solution Alpha", DC_FAMILY_SUUNTO_EON, 0, NULL}, - {"Suunto", "Solution Nitrox", 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, DC_TRANSPORT_SERIAL, NULL}, + {"Suunto", "Solution Nitrox", DC_FAMILY_SUUNTO_EON, 0, DC_TRANSPORT_SERIAL, NULL}, /* Suunto Vyper */ - {"Suunto", "Spyder", DC_FAMILY_SUUNTO_VYPER, 0x01, NULL}, - {"Suunto", "Stinger", DC_FAMILY_SUUNTO_VYPER, 0x03, NULL}, - {"Suunto", "Mosquito", DC_FAMILY_SUUNTO_VYPER, 0x04, NULL}, - {"Suunto", "D3", DC_FAMILY_SUUNTO_VYPER, 0x05, NULL}, - {"Suunto", "Vyper", DC_FAMILY_SUUNTO_VYPER, 0x0A, NULL}, - {"Suunto", "Vytec", DC_FAMILY_SUUNTO_VYPER, 0X0B, NULL}, - {"Suunto", "Cobra", DC_FAMILY_SUUNTO_VYPER, 0X0C, NULL}, - {"Suunto", "Gekko", DC_FAMILY_SUUNTO_VYPER, 0X0D, NULL}, - {"Suunto", "Zoop", DC_FAMILY_SUUNTO_VYPER, 0x16, NULL}, + {"Suunto", "Spyder", DC_FAMILY_SUUNTO_VYPER, 0x01, DC_TRANSPORT_SERIAL, NULL}, + {"Suunto", "Stinger", DC_FAMILY_SUUNTO_VYPER, 0x03, DC_TRANSPORT_SERIAL, NULL}, + {"Suunto", "Mosquito", DC_FAMILY_SUUNTO_VYPER, 0x04, DC_TRANSPORT_SERIAL, NULL}, + {"Suunto", "D3", DC_FAMILY_SUUNTO_VYPER, 0x05, DC_TRANSPORT_SERIAL, NULL}, + {"Suunto", "Vyper", DC_FAMILY_SUUNTO_VYPER, 0x0A, DC_TRANSPORT_SERIAL, NULL}, + {"Suunto", "Vytec", DC_FAMILY_SUUNTO_VYPER, 0X0B, DC_TRANSPORT_SERIAL, NULL}, + {"Suunto", "Cobra", DC_FAMILY_SUUNTO_VYPER, 0X0C, DC_TRANSPORT_SERIAL, NULL}, + {"Suunto", "Gekko", DC_FAMILY_SUUNTO_VYPER, 0X0D, DC_TRANSPORT_SERIAL, NULL}, + {"Suunto", "Zoop", DC_FAMILY_SUUNTO_VYPER, 0x16, DC_TRANSPORT_SERIAL, NULL}, /* Suunto Vyper 2 */ - {"Suunto", "Vyper 2", DC_FAMILY_SUUNTO_VYPER2, 0x10, NULL}, - {"Suunto", "Cobra 2", DC_FAMILY_SUUNTO_VYPER2, 0x11, NULL}, - {"Suunto", "Vyper Air", DC_FAMILY_SUUNTO_VYPER2, 0x13, NULL}, - {"Suunto", "Cobra 3", DC_FAMILY_SUUNTO_VYPER2, 0x14, NULL}, - {"Suunto", "HelO2", DC_FAMILY_SUUNTO_VYPER2, 0x15, NULL}, + {"Suunto", "Vyper 2", DC_FAMILY_SUUNTO_VYPER2, 0x10, DC_TRANSPORT_SERIAL, NULL}, + {"Suunto", "Cobra 2", DC_FAMILY_SUUNTO_VYPER2, 0x11, DC_TRANSPORT_SERIAL, NULL}, + {"Suunto", "Vyper Air", DC_FAMILY_SUUNTO_VYPER2, 0x13, DC_TRANSPORT_SERIAL, NULL}, + {"Suunto", "Cobra 3", DC_FAMILY_SUUNTO_VYPER2, 0x14, DC_TRANSPORT_SERIAL, NULL}, + {"Suunto", "HelO2", DC_FAMILY_SUUNTO_VYPER2, 0x15, DC_TRANSPORT_SERIAL, NULL}, /* Suunto D9 */ - {"Suunto", "D9", DC_FAMILY_SUUNTO_D9, 0x0E, NULL}, - {"Suunto", "D6", DC_FAMILY_SUUNTO_D9, 0x0F, NULL}, - {"Suunto", "D4", DC_FAMILY_SUUNTO_D9, 0x12, NULL}, - {"Suunto", "D4i", DC_FAMILY_SUUNTO_D9, 0x19, NULL}, - {"Suunto", "D6i", DC_FAMILY_SUUNTO_D9, 0x1A, NULL}, - {"Suunto", "D9tx", DC_FAMILY_SUUNTO_D9, 0x1B, NULL}, - {"Suunto", "DX", DC_FAMILY_SUUNTO_D9, 0x1C, NULL}, - {"Suunto", "Vyper Novo", DC_FAMILY_SUUNTO_D9, 0x1D, NULL}, - {"Suunto", "Zoop Novo", DC_FAMILY_SUUNTO_D9, 0x1E, NULL}, - {"Suunto", "D4f", DC_FAMILY_SUUNTO_D9, 0x20, NULL}, + {"Suunto", "D9", DC_FAMILY_SUUNTO_D9, 0x0E, DC_TRANSPORT_SERIAL, NULL}, + {"Suunto", "D6", DC_FAMILY_SUUNTO_D9, 0x0F, DC_TRANSPORT_SERIAL, NULL}, + {"Suunto", "D4", DC_FAMILY_SUUNTO_D9, 0x12, DC_TRANSPORT_SERIAL, NULL}, + {"Suunto", "D4i", DC_FAMILY_SUUNTO_D9, 0x19, DC_TRANSPORT_SERIAL, NULL}, + {"Suunto", "D6i", DC_FAMILY_SUUNTO_D9, 0x1A, DC_TRANSPORT_SERIAL, NULL}, + {"Suunto", "D9tx", DC_FAMILY_SUUNTO_D9, 0x1B, DC_TRANSPORT_SERIAL, NULL}, + {"Suunto", "DX", DC_FAMILY_SUUNTO_D9, 0x1C, DC_TRANSPORT_SERIAL, NULL}, + {"Suunto", "Vyper Novo", DC_FAMILY_SUUNTO_D9, 0x1D, DC_TRANSPORT_SERIAL, NULL}, + {"Suunto", "Zoop Novo", DC_FAMILY_SUUNTO_D9, 0x1E, DC_TRANSPORT_SERIAL, NULL}, + {"Suunto", "D4f", DC_FAMILY_SUUNTO_D9, 0x20, DC_TRANSPORT_SERIAL, NULL}, /* Suunto EON Steel */ -#ifdef USBHID - {"Suunto", "EON Steel", DC_FAMILY_SUUNTO_EONSTEEL, 0, dc_filter_suunto}, - {"Suunto", "EON Core", DC_FAMILY_SUUNTO_EONSTEEL, 1, dc_filter_suunto}, -#endif + {"Suunto", "EON Steel", DC_FAMILY_SUUNTO_EONSTEEL, 0, DC_TRANSPORT_USBHID, dc_filter_suunto}, + {"Suunto", "EON Core", DC_FAMILY_SUUNTO_EONSTEEL, 1, DC_TRANSPORT_USBHID, dc_filter_suunto}, /* Uwatec Aladin */ - {"Uwatec", "Aladin Air Twin", DC_FAMILY_UWATEC_ALADIN, 0x1C, NULL}, - {"Uwatec", "Aladin Sport Plus", DC_FAMILY_UWATEC_ALADIN, 0x3E, NULL}, - {"Uwatec", "Aladin Pro", DC_FAMILY_UWATEC_ALADIN, 0x3F, NULL}, - {"Uwatec", "Aladin Air Z", DC_FAMILY_UWATEC_ALADIN, 0x44, NULL}, - {"Uwatec", "Aladin Air Z O2", DC_FAMILY_UWATEC_ALADIN, 0xA4, NULL}, - {"Uwatec", "Aladin Air Z Nitrox", DC_FAMILY_UWATEC_ALADIN, 0xF4, NULL}, - {"Uwatec", "Aladin Pro Ultra", DC_FAMILY_UWATEC_ALADIN, 0xFF, NULL}, + {"Uwatec", "Aladin Air Twin", DC_FAMILY_UWATEC_ALADIN, 0x1C, DC_TRANSPORT_SERIAL, NULL}, + {"Uwatec", "Aladin Sport Plus", DC_FAMILY_UWATEC_ALADIN, 0x3E, DC_TRANSPORT_SERIAL, NULL}, + {"Uwatec", "Aladin Pro", DC_FAMILY_UWATEC_ALADIN, 0x3F, DC_TRANSPORT_SERIAL, NULL}, + {"Uwatec", "Aladin Air Z", DC_FAMILY_UWATEC_ALADIN, 0x44, DC_TRANSPORT_SERIAL, 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, DC_TRANSPORT_SERIAL, NULL}, + {"Uwatec", "Aladin Pro Ultra", DC_FAMILY_UWATEC_ALADIN, 0xFF, DC_TRANSPORT_SERIAL, NULL}, /* Uwatec Memomouse */ - {"Uwatec", "Memomouse", DC_FAMILY_UWATEC_MEMOMOUSE, 0, NULL}, + {"Uwatec", "Memomouse", DC_FAMILY_UWATEC_MEMOMOUSE, 0, DC_TRANSPORT_SERIAL, NULL}, /* Uwatec Smart */ -#ifdef IRDA - {"Uwatec", "Smart Pro", DC_FAMILY_UWATEC_SMART, 0x10, dc_filter_uwatec}, - {"Uwatec", "Galileo Sol", DC_FAMILY_UWATEC_SMART, 0x11, dc_filter_uwatec}, - {"Uwatec", "Galileo Luna", DC_FAMILY_UWATEC_SMART, 0x11, dc_filter_uwatec}, - {"Uwatec", "Galileo Terra", DC_FAMILY_UWATEC_SMART, 0x11, dc_filter_uwatec}, - {"Uwatec", "Aladin Tec", DC_FAMILY_UWATEC_SMART, 0x12, dc_filter_uwatec}, - {"Uwatec", "Aladin Prime", DC_FAMILY_UWATEC_SMART, 0x12, dc_filter_uwatec}, - {"Uwatec", "Aladin Tec 2G", DC_FAMILY_UWATEC_SMART, 0x13, dc_filter_uwatec}, - {"Uwatec", "Aladin 2G", DC_FAMILY_UWATEC_SMART, 0x13, dc_filter_uwatec}, - {"Subgear","XP-10", DC_FAMILY_UWATEC_SMART, 0x13, dc_filter_uwatec}, - {"Uwatec", "Smart Com", DC_FAMILY_UWATEC_SMART, 0x14, dc_filter_uwatec}, - {"Uwatec", "Aladin 2G", DC_FAMILY_UWATEC_SMART, 0x15, dc_filter_uwatec}, - {"Uwatec", "Aladin Tec 3G", DC_FAMILY_UWATEC_SMART, 0x15, dc_filter_uwatec}, - {"Uwatec", "Aladin Sport", DC_FAMILY_UWATEC_SMART, 0x15, dc_filter_uwatec}, - {"Subgear","XP-3G", DC_FAMILY_UWATEC_SMART, 0x15, dc_filter_uwatec}, - {"Uwatec", "Smart Tec", DC_FAMILY_UWATEC_SMART, 0x18, dc_filter_uwatec}, - {"Uwatec", "Galileo Trimix",DC_FAMILY_UWATEC_SMART, 0x19, dc_filter_uwatec}, - {"Uwatec", "Smart Z", DC_FAMILY_UWATEC_SMART, 0x1C, dc_filter_uwatec}, - {"Subgear","XP Air", DC_FAMILY_UWATEC_SMART, 0x1C, dc_filter_uwatec}, -#endif + {"Uwatec", "Smart Pro", DC_FAMILY_UWATEC_SMART, 0x10, DC_TRANSPORT_IRDA, dc_filter_uwatec}, + {"Uwatec", "Galileo Sol", DC_FAMILY_UWATEC_SMART, 0x11, DC_TRANSPORT_IRDA, dc_filter_uwatec}, + {"Uwatec", "Galileo Luna", DC_FAMILY_UWATEC_SMART, 0x11, DC_TRANSPORT_IRDA, dc_filter_uwatec}, + {"Uwatec", "Galileo Terra", DC_FAMILY_UWATEC_SMART, 0x11, DC_TRANSPORT_IRDA, dc_filter_uwatec}, + {"Uwatec", "Aladin Tec", DC_FAMILY_UWATEC_SMART, 0x12, DC_TRANSPORT_IRDA, dc_filter_uwatec}, + {"Uwatec", "Aladin Prime", DC_FAMILY_UWATEC_SMART, 0x12, DC_TRANSPORT_IRDA, dc_filter_uwatec}, + {"Uwatec", "Aladin Tec 2G", DC_FAMILY_UWATEC_SMART, 0x13, DC_TRANSPORT_IRDA, dc_filter_uwatec}, + {"Uwatec", "Aladin 2G", DC_FAMILY_UWATEC_SMART, 0x13, DC_TRANSPORT_IRDA, dc_filter_uwatec}, + {"Subgear","XP-10", DC_FAMILY_UWATEC_SMART, 0x13, DC_TRANSPORT_IRDA, dc_filter_uwatec}, + {"Uwatec", "Smart Com", DC_FAMILY_UWATEC_SMART, 0x14, DC_TRANSPORT_IRDA, dc_filter_uwatec}, + {"Uwatec", "Aladin 2G", DC_FAMILY_UWATEC_SMART, 0x15, DC_TRANSPORT_IRDA, dc_filter_uwatec}, + {"Uwatec", "Aladin Tec 3G", DC_FAMILY_UWATEC_SMART, 0x15, DC_TRANSPORT_IRDA, dc_filter_uwatec}, + {"Uwatec", "Aladin Sport", DC_FAMILY_UWATEC_SMART, 0x15, DC_TRANSPORT_IRDA, dc_filter_uwatec}, + {"Subgear","XP-3G", DC_FAMILY_UWATEC_SMART, 0x15, DC_TRANSPORT_IRDA, dc_filter_uwatec}, + {"Uwatec", "Smart Tec", DC_FAMILY_UWATEC_SMART, 0x18, DC_TRANSPORT_IRDA, dc_filter_uwatec}, + {"Uwatec", "Galileo Trimix",DC_FAMILY_UWATEC_SMART, 0x19, DC_TRANSPORT_IRDA, dc_filter_uwatec}, + {"Uwatec", "Smart Z", DC_FAMILY_UWATEC_SMART, 0x1C, DC_TRANSPORT_IRDA, dc_filter_uwatec}, + {"Subgear","XP Air", DC_FAMILY_UWATEC_SMART, 0x1C, DC_TRANSPORT_IRDA, dc_filter_uwatec}, /* Scubapro/Uwatec Meridian */ - {"Scubapro", "Meridian", DC_FAMILY_UWATEC_MERIDIAN, 0x20, NULL}, - {"Scubapro", "Mantis", DC_FAMILY_UWATEC_MERIDIAN, 0x20, NULL}, - {"Scubapro", "Chromis", DC_FAMILY_UWATEC_MERIDIAN, 0x24, NULL}, - {"Scubapro", "Mantis 2", DC_FAMILY_UWATEC_MERIDIAN, 0x26, NULL}, + {"Scubapro", "Meridian", DC_FAMILY_UWATEC_MERIDIAN, 0x20, DC_TRANSPORT_SERIAL, NULL}, + {"Scubapro", "Mantis", DC_FAMILY_UWATEC_MERIDIAN, 0x20, DC_TRANSPORT_SERIAL, NULL}, + {"Scubapro", "Chromis", DC_FAMILY_UWATEC_MERIDIAN, 0x24, DC_TRANSPORT_SERIAL, NULL}, + {"Scubapro", "Mantis 2", DC_FAMILY_UWATEC_MERIDIAN, 0x26, DC_TRANSPORT_SERIAL, NULL}, /* Scubapro G2 */ -#ifdef USBHID - {"Scubapro", "Aladin Sport Matrix", DC_FAMILY_UWATEC_G2, 0x17, dc_filter_uwatec}, - {"Scubapro", "Aladin Square", DC_FAMILY_UWATEC_G2, 0x22, dc_filter_uwatec}, - {"Scubapro", "G2", DC_FAMILY_UWATEC_G2, 0x32, dc_filter_uwatec}, -#endif + {"Scubapro", "Aladin Sport Matrix", DC_FAMILY_UWATEC_G2, 0x17, DC_TRANSPORT_NONE, dc_filter_uwatec}, + {"Scubapro", "Aladin Square", DC_FAMILY_UWATEC_G2, 0x22, DC_TRANSPORT_USBHID, dc_filter_uwatec}, + {"Scubapro", "G2", DC_FAMILY_UWATEC_G2, 0x32, DC_TRANSPORT_USBHID, dc_filter_uwatec}, /* Reefnet */ - {"Reefnet", "Sensus", DC_FAMILY_REEFNET_SENSUS, 1, NULL}, - {"Reefnet", "Sensus Pro", DC_FAMILY_REEFNET_SENSUSPRO, 2, NULL}, - {"Reefnet", "Sensus Ultra", DC_FAMILY_REEFNET_SENSUSULTRA, 3, NULL}, + {"Reefnet", "Sensus", DC_FAMILY_REEFNET_SENSUS, 1, DC_TRANSPORT_SERIAL, NULL}, + {"Reefnet", "Sensus Pro", DC_FAMILY_REEFNET_SENSUSPRO, 2, DC_TRANSPORT_SERIAL, NULL}, + {"Reefnet", "Sensus Ultra", DC_FAMILY_REEFNET_SENSUSULTRA, 3, DC_TRANSPORT_SERIAL, NULL}, /* Oceanic VT Pro */ - {"Aeris", "500 AI", DC_FAMILY_OCEANIC_VTPRO, 0x4151, NULL}, - {"Oceanic", "Versa Pro", DC_FAMILY_OCEANIC_VTPRO, 0x4155, NULL}, - {"Aeris", "Atmos 2", DC_FAMILY_OCEANIC_VTPRO, 0x4158, NULL}, - {"Oceanic", "Pro Plus 2", DC_FAMILY_OCEANIC_VTPRO, 0x4159, NULL}, - {"Aeris", "Atmos AI", DC_FAMILY_OCEANIC_VTPRO, 0x4244, NULL}, - {"Oceanic", "VT Pro", DC_FAMILY_OCEANIC_VTPRO, 0x4245, NULL}, - {"Sherwood", "Wisdom", DC_FAMILY_OCEANIC_VTPRO, 0x4246, NULL}, - {"Aeris", "Elite", DC_FAMILY_OCEANIC_VTPRO, 0x424F, NULL}, + {"Aeris", "500 AI", DC_FAMILY_OCEANIC_VTPRO, 0x4151, DC_TRANSPORT_SERIAL, NULL}, + {"Oceanic", "Versa Pro", DC_FAMILY_OCEANIC_VTPRO, 0x4155, DC_TRANSPORT_SERIAL, NULL}, + {"Aeris", "Atmos 2", DC_FAMILY_OCEANIC_VTPRO, 0x4158, DC_TRANSPORT_SERIAL, NULL}, + {"Oceanic", "Pro Plus 2", DC_FAMILY_OCEANIC_VTPRO, 0x4159, DC_TRANSPORT_SERIAL, NULL}, + {"Aeris", "Atmos AI", DC_FAMILY_OCEANIC_VTPRO, 0x4244, DC_TRANSPORT_SERIAL, NULL}, + {"Oceanic", "VT Pro", DC_FAMILY_OCEANIC_VTPRO, 0x4245, DC_TRANSPORT_SERIAL, NULL}, + {"Sherwood", "Wisdom", DC_FAMILY_OCEANIC_VTPRO, 0x4246, DC_TRANSPORT_SERIAL, NULL}, + {"Aeris", "Elite", DC_FAMILY_OCEANIC_VTPRO, 0x424F, DC_TRANSPORT_SERIAL, NULL}, /* Oceanic Veo 250 */ - {"Genesis", "React Pro", DC_FAMILY_OCEANIC_VEO250, 0x4247, NULL}, - {"Oceanic", "Veo 200", DC_FAMILY_OCEANIC_VEO250, 0x424B, NULL}, - {"Oceanic", "Veo 250", DC_FAMILY_OCEANIC_VEO250, 0x424C, NULL}, - {"Seemann", "XP5", DC_FAMILY_OCEANIC_VEO250, 0x4251, NULL}, - {"Oceanic", "Veo 180", DC_FAMILY_OCEANIC_VEO250, 0x4252, NULL}, - {"Aeris", "XR-2", DC_FAMILY_OCEANIC_VEO250, 0x4255, NULL}, - {"Sherwood", "Insight", DC_FAMILY_OCEANIC_VEO250, 0x425A, NULL}, - {"Hollis", "DG02", DC_FAMILY_OCEANIC_VEO250, 0x4352, NULL}, + {"Genesis", "React Pro", DC_FAMILY_OCEANIC_VEO250, 0x4247, DC_TRANSPORT_SERIAL, NULL}, + {"Oceanic", "Veo 200", DC_FAMILY_OCEANIC_VEO250, 0x424B, DC_TRANSPORT_SERIAL, NULL}, + {"Oceanic", "Veo 250", DC_FAMILY_OCEANIC_VEO250, 0x424C, DC_TRANSPORT_SERIAL, NULL}, + {"Seemann", "XP5", DC_FAMILY_OCEANIC_VEO250, 0x4251, DC_TRANSPORT_SERIAL, NULL}, + {"Oceanic", "Veo 180", DC_FAMILY_OCEANIC_VEO250, 0x4252, DC_TRANSPORT_SERIAL, NULL}, + {"Aeris", "XR-2", DC_FAMILY_OCEANIC_VEO250, 0x4255, DC_TRANSPORT_SERIAL, NULL}, + {"Sherwood", "Insight", DC_FAMILY_OCEANIC_VEO250, 0x425A, DC_TRANSPORT_SERIAL, NULL}, + {"Hollis", "DG02", DC_FAMILY_OCEANIC_VEO250, 0x4352, DC_TRANSPORT_SERIAL, NULL}, /* Oceanic Atom 2.0 */ - {"Oceanic", "Atom 1.0", DC_FAMILY_OCEANIC_ATOM2, 0x4250, NULL}, - {"Aeris", "Epic", DC_FAMILY_OCEANIC_ATOM2, 0x4257, NULL}, - {"Oceanic", "VT3", DC_FAMILY_OCEANIC_ATOM2, 0x4258, NULL}, - {"Aeris", "Elite T3", DC_FAMILY_OCEANIC_ATOM2, 0x4259, NULL}, - {"Oceanic", "Atom 2.0", DC_FAMILY_OCEANIC_ATOM2, 0x4342, NULL}, - {"Oceanic", "Geo", DC_FAMILY_OCEANIC_ATOM2, 0x4344, NULL}, - {"Aeris", "Manta", DC_FAMILY_OCEANIC_ATOM2, 0x4345, NULL}, - {"Aeris", "XR-1 NX", DC_FAMILY_OCEANIC_ATOM2, 0x4346, NULL}, - {"Oceanic", "Datamask", DC_FAMILY_OCEANIC_ATOM2, 0x4347, NULL}, - {"Aeris", "Compumask", DC_FAMILY_OCEANIC_ATOM2, 0x4348, NULL}, - {"Aeris", "F10", DC_FAMILY_OCEANIC_ATOM2, 0x434D, NULL}, - {"Oceanic", "OC1", DC_FAMILY_OCEANIC_ATOM2, 0x434E, NULL}, - {"Sherwood", "Wisdom 2", DC_FAMILY_OCEANIC_ATOM2, 0x4350, NULL}, - {"Sherwood", "Insight 2", DC_FAMILY_OCEANIC_ATOM2, 0x4353, NULL}, - {"Genesis", "React Pro White", DC_FAMILY_OCEANIC_ATOM2, 0x4354, NULL}, - {"Tusa", "Element II (IQ-750)", DC_FAMILY_OCEANIC_ATOM2, 0x4357, NULL}, - {"Oceanic", "Veo 1.0", DC_FAMILY_OCEANIC_ATOM2, 0x4358, NULL}, - {"Oceanic", "Veo 2.0", DC_FAMILY_OCEANIC_ATOM2, 0x4359, NULL}, - {"Oceanic", "Veo 3.0", DC_FAMILY_OCEANIC_ATOM2, 0x435A, NULL}, - {"Tusa", "Zen (IQ-900)", DC_FAMILY_OCEANIC_ATOM2, 0x4441, NULL}, - {"Tusa", "Zen Air (IQ-950)", DC_FAMILY_OCEANIC_ATOM2, 0x4442, NULL}, - {"Aeris", "Atmos AI 2", DC_FAMILY_OCEANIC_ATOM2, 0x4443, NULL}, - {"Oceanic", "Pro Plus 2.1", DC_FAMILY_OCEANIC_ATOM2, 0x4444, NULL}, - {"Oceanic", "Geo 2.0", DC_FAMILY_OCEANIC_ATOM2, 0x4446, NULL}, - {"Oceanic", "VT4", DC_FAMILY_OCEANIC_ATOM2, 0x4447, NULL}, - {"Oceanic", "OC1", DC_FAMILY_OCEANIC_ATOM2, 0x4449, NULL}, - {"Beuchat", "Voyager 2G", DC_FAMILY_OCEANIC_ATOM2, 0x444B, NULL}, - {"Oceanic", "Atom 3.0", DC_FAMILY_OCEANIC_ATOM2, 0x444C, NULL}, - {"Hollis", "DG03", DC_FAMILY_OCEANIC_ATOM2, 0x444D, NULL}, - {"Oceanic", "OCS", DC_FAMILY_OCEANIC_ATOM2, 0x4450, NULL}, - {"Oceanic", "OC1", DC_FAMILY_OCEANIC_ATOM2, 0x4451, NULL}, - {"Oceanic", "VT 4.1", DC_FAMILY_OCEANIC_ATOM2, 0x4452, NULL}, - {"Aeris", "Epic", DC_FAMILY_OCEANIC_ATOM2, 0x4453, NULL}, - {"Aeris", "Elite T3", DC_FAMILY_OCEANIC_ATOM2, 0x4455, NULL}, - {"Oceanic", "Atom 3.1", DC_FAMILY_OCEANIC_ATOM2, 0x4456, NULL}, - {"Aeris", "A300 AI", DC_FAMILY_OCEANIC_ATOM2, 0x4457, NULL}, - {"Sherwood", "Wisdom 3", DC_FAMILY_OCEANIC_ATOM2, 0x4458, NULL}, - {"Aeris", "A300", DC_FAMILY_OCEANIC_ATOM2, 0x445A, NULL}, - {"Hollis", "TX1", DC_FAMILY_OCEANIC_ATOM2, 0x4542, NULL}, - {"Beuchat", "Mundial 2", DC_FAMILY_OCEANIC_ATOM2, 0x4543, NULL}, - {"Sherwood", "Amphos", DC_FAMILY_OCEANIC_ATOM2, 0x4545, NULL}, - {"Sherwood", "Amphos Air", DC_FAMILY_OCEANIC_ATOM2, 0x4546, NULL}, - {"Oceanic", "Pro Plus 3", DC_FAMILY_OCEANIC_ATOM2, 0x4548, NULL}, - {"Aeris", "F11", DC_FAMILY_OCEANIC_ATOM2, 0x4549, NULL}, - {"Oceanic", "OCi", DC_FAMILY_OCEANIC_ATOM2, 0x454B, NULL}, - {"Aeris", "A300CS", DC_FAMILY_OCEANIC_ATOM2, 0x454C, NULL}, - {"Beuchat", "Mundial 3", DC_FAMILY_OCEANIC_ATOM2, 0x4550, NULL}, - {"Oceanic", "F10", DC_FAMILY_OCEANIC_ATOM2, 0x4553, NULL}, - {"Oceanic", "F11", DC_FAMILY_OCEANIC_ATOM2, 0x4554, NULL}, - {"Subgear", "XP-Air", DC_FAMILY_OCEANIC_ATOM2, 0x4555, NULL}, - {"Sherwood", "Vision", DC_FAMILY_OCEANIC_ATOM2, 0x4556, NULL}, - {"Oceanic", "VTX", DC_FAMILY_OCEANIC_ATOM2, 0x4557, NULL}, - {"Aqualung", "i300", DC_FAMILY_OCEANIC_ATOM2, 0x4559, NULL}, - {"Aqualung", "i750TC", DC_FAMILY_OCEANIC_ATOM2, 0x455A, NULL}, - {"Aqualung", "i450T", DC_FAMILY_OCEANIC_ATOM2, 0x4641, NULL}, - {"Aqualung", "i550", DC_FAMILY_OCEANIC_ATOM2, 0x4642, NULL}, - {"Aqualung", "i200", DC_FAMILY_OCEANIC_ATOM2, 0x4646, NULL}, + {"Oceanic", "Atom 1.0", DC_FAMILY_OCEANIC_ATOM2, 0x4250, DC_TRANSPORT_SERIAL, NULL}, + {"Aeris", "Epic", DC_FAMILY_OCEANIC_ATOM2, 0x4257, DC_TRANSPORT_SERIAL, NULL}, + {"Oceanic", "VT3", DC_FAMILY_OCEANIC_ATOM2, 0x4258, DC_TRANSPORT_SERIAL, NULL}, + {"Aeris", "Elite T3", DC_FAMILY_OCEANIC_ATOM2, 0x4259, DC_TRANSPORT_SERIAL, NULL}, + {"Oceanic", "Atom 2.0", DC_FAMILY_OCEANIC_ATOM2, 0x4342, DC_TRANSPORT_SERIAL, NULL}, + {"Oceanic", "Geo", DC_FAMILY_OCEANIC_ATOM2, 0x4344, DC_TRANSPORT_SERIAL, NULL}, + {"Aeris", "Manta", DC_FAMILY_OCEANIC_ATOM2, 0x4345, DC_TRANSPORT_SERIAL, NULL}, + {"Aeris", "XR-1 NX", DC_FAMILY_OCEANIC_ATOM2, 0x4346, DC_TRANSPORT_SERIAL, NULL}, + {"Oceanic", "Datamask", DC_FAMILY_OCEANIC_ATOM2, 0x4347, DC_TRANSPORT_SERIAL, NULL}, + {"Aeris", "Compumask", DC_FAMILY_OCEANIC_ATOM2, 0x4348, DC_TRANSPORT_SERIAL, NULL}, + {"Aeris", "F10", DC_FAMILY_OCEANIC_ATOM2, 0x434D, DC_TRANSPORT_SERIAL, NULL}, + {"Oceanic", "OC1", DC_FAMILY_OCEANIC_ATOM2, 0x434E, DC_TRANSPORT_SERIAL, NULL}, + {"Sherwood", "Wisdom 2", DC_FAMILY_OCEANIC_ATOM2, 0x4350, DC_TRANSPORT_SERIAL, NULL}, + {"Sherwood", "Insight 2", DC_FAMILY_OCEANIC_ATOM2, 0x4353, DC_TRANSPORT_SERIAL, NULL}, + {"Genesis", "React Pro White", DC_FAMILY_OCEANIC_ATOM2, 0x4354, DC_TRANSPORT_SERIAL, NULL}, + {"Tusa", "Element II (IQ-750)", DC_FAMILY_OCEANIC_ATOM2, 0x4357, DC_TRANSPORT_SERIAL, NULL}, + {"Oceanic", "Veo 1.0", DC_FAMILY_OCEANIC_ATOM2, 0x4358, DC_TRANSPORT_SERIAL, NULL}, + {"Oceanic", "Veo 2.0", DC_FAMILY_OCEANIC_ATOM2, 0x4359, DC_TRANSPORT_SERIAL, NULL}, + {"Oceanic", "Veo 3.0", DC_FAMILY_OCEANIC_ATOM2, 0x435A, DC_TRANSPORT_SERIAL, NULL}, + {"Tusa", "Zen (IQ-900)", DC_FAMILY_OCEANIC_ATOM2, 0x4441, DC_TRANSPORT_SERIAL, NULL}, + {"Tusa", "Zen Air (IQ-950)", DC_FAMILY_OCEANIC_ATOM2, 0x4442, DC_TRANSPORT_SERIAL, NULL}, + {"Aeris", "Atmos AI 2", DC_FAMILY_OCEANIC_ATOM2, 0x4443, DC_TRANSPORT_SERIAL, NULL}, + {"Oceanic", "Pro Plus 2.1", DC_FAMILY_OCEANIC_ATOM2, 0x4444, DC_TRANSPORT_SERIAL, NULL}, + {"Oceanic", "Geo 2.0", DC_FAMILY_OCEANIC_ATOM2, 0x4446, DC_TRANSPORT_SERIAL, NULL}, + {"Oceanic", "VT4", DC_FAMILY_OCEANIC_ATOM2, 0x4447, DC_TRANSPORT_SERIAL, NULL}, + {"Oceanic", "OC1", DC_FAMILY_OCEANIC_ATOM2, 0x4449, DC_TRANSPORT_SERIAL, NULL}, + {"Beuchat", "Voyager 2G", DC_FAMILY_OCEANIC_ATOM2, 0x444B, DC_TRANSPORT_SERIAL, NULL}, + {"Oceanic", "Atom 3.0", DC_FAMILY_OCEANIC_ATOM2, 0x444C, DC_TRANSPORT_SERIAL, NULL}, + {"Hollis", "DG03", DC_FAMILY_OCEANIC_ATOM2, 0x444D, DC_TRANSPORT_SERIAL, NULL}, + {"Oceanic", "OCS", DC_FAMILY_OCEANIC_ATOM2, 0x4450, DC_TRANSPORT_SERIAL, NULL}, + {"Oceanic", "OC1", DC_FAMILY_OCEANIC_ATOM2, 0x4451, DC_TRANSPORT_SERIAL, NULL}, + {"Oceanic", "VT 4.1", DC_FAMILY_OCEANIC_ATOM2, 0x4452, DC_TRANSPORT_SERIAL, NULL}, + {"Aeris", "Epic", DC_FAMILY_OCEANIC_ATOM2, 0x4453, DC_TRANSPORT_SERIAL, NULL}, + {"Aeris", "Elite T3", DC_FAMILY_OCEANIC_ATOM2, 0x4455, DC_TRANSPORT_SERIAL, NULL}, + {"Oceanic", "Atom 3.1", DC_FAMILY_OCEANIC_ATOM2, 0x4456, DC_TRANSPORT_SERIAL, NULL}, + {"Aeris", "A300 AI", DC_FAMILY_OCEANIC_ATOM2, 0x4457, DC_TRANSPORT_SERIAL, NULL}, + {"Sherwood", "Wisdom 3", DC_FAMILY_OCEANIC_ATOM2, 0x4458, DC_TRANSPORT_SERIAL, NULL}, + {"Aeris", "A300", DC_FAMILY_OCEANIC_ATOM2, 0x445A, DC_TRANSPORT_SERIAL, NULL}, + {"Hollis", "TX1", DC_FAMILY_OCEANIC_ATOM2, 0x4542, DC_TRANSPORT_SERIAL, NULL}, + {"Beuchat", "Mundial 2", DC_FAMILY_OCEANIC_ATOM2, 0x4543, DC_TRANSPORT_SERIAL, NULL}, + {"Sherwood", "Amphos", DC_FAMILY_OCEANIC_ATOM2, 0x4545, DC_TRANSPORT_SERIAL, NULL}, + {"Sherwood", "Amphos Air", DC_FAMILY_OCEANIC_ATOM2, 0x4546, DC_TRANSPORT_SERIAL, NULL}, + {"Oceanic", "Pro Plus 3", DC_FAMILY_OCEANIC_ATOM2, 0x4548, DC_TRANSPORT_SERIAL, NULL}, + {"Aeris", "F11", DC_FAMILY_OCEANIC_ATOM2, 0x4549, DC_TRANSPORT_SERIAL, NULL}, + {"Oceanic", "OCi", DC_FAMILY_OCEANIC_ATOM2, 0x454B, DC_TRANSPORT_SERIAL, NULL}, + {"Aeris", "A300CS", DC_FAMILY_OCEANIC_ATOM2, 0x454C, DC_TRANSPORT_SERIAL, NULL}, + {"Beuchat", "Mundial 3", DC_FAMILY_OCEANIC_ATOM2, 0x4550, DC_TRANSPORT_SERIAL, NULL}, + {"Oceanic", "F10", DC_FAMILY_OCEANIC_ATOM2, 0x4553, DC_TRANSPORT_SERIAL, NULL}, + {"Oceanic", "F11", DC_FAMILY_OCEANIC_ATOM2, 0x4554, DC_TRANSPORT_SERIAL, NULL}, + {"Subgear", "XP-Air", DC_FAMILY_OCEANIC_ATOM2, 0x4555, DC_TRANSPORT_SERIAL, NULL}, + {"Sherwood", "Vision", DC_FAMILY_OCEANIC_ATOM2, 0x4556, DC_TRANSPORT_SERIAL, NULL}, + {"Oceanic", "VTX", DC_FAMILY_OCEANIC_ATOM2, 0x4557, DC_TRANSPORT_SERIAL, NULL}, + {"Aqualung", "i300", DC_FAMILY_OCEANIC_ATOM2, 0x4559, DC_TRANSPORT_SERIAL, NULL}, + {"Aqualung", "i750TC", DC_FAMILY_OCEANIC_ATOM2, 0x455A, DC_TRANSPORT_SERIAL, NULL}, + {"Aqualung", "i450T", DC_FAMILY_OCEANIC_ATOM2, 0x4641, DC_TRANSPORT_SERIAL, NULL}, + {"Aqualung", "i550", DC_FAMILY_OCEANIC_ATOM2, 0x4642, DC_TRANSPORT_SERIAL, NULL}, + {"Aqualung", "i200", DC_FAMILY_OCEANIC_ATOM2, 0x4646, DC_TRANSPORT_SERIAL, NULL}, /* Mares Nemo */ - {"Mares", "Nemo", DC_FAMILY_MARES_NEMO, 0, NULL}, - {"Mares", "Nemo Steel", DC_FAMILY_MARES_NEMO, 0, NULL}, - {"Mares", "Nemo Titanium",DC_FAMILY_MARES_NEMO, 0, NULL}, - {"Mares", "Nemo Excel", DC_FAMILY_MARES_NEMO, 17, NULL}, - {"Mares", "Nemo Apneist", DC_FAMILY_MARES_NEMO, 18, NULL}, + {"Mares", "Nemo", DC_FAMILY_MARES_NEMO, 0, DC_TRANSPORT_SERIAL, NULL}, + {"Mares", "Nemo Steel", DC_FAMILY_MARES_NEMO, 0, DC_TRANSPORT_SERIAL, NULL}, + {"Mares", "Nemo Titanium",DC_FAMILY_MARES_NEMO, 0, DC_TRANSPORT_SERIAL, NULL}, + {"Mares", "Nemo Excel", DC_FAMILY_MARES_NEMO, 17, DC_TRANSPORT_SERIAL, NULL}, + {"Mares", "Nemo Apneist", DC_FAMILY_MARES_NEMO, 18, DC_TRANSPORT_SERIAL, NULL}, /* Mares Puck */ - {"Mares", "Puck", DC_FAMILY_MARES_PUCK, 7, NULL}, - {"Mares", "Puck Air", DC_FAMILY_MARES_PUCK, 19, NULL}, - {"Mares", "Nemo Air", DC_FAMILY_MARES_PUCK, 4, NULL}, - {"Mares", "Nemo Wide", DC_FAMILY_MARES_PUCK, 1, NULL}, + {"Mares", "Puck", DC_FAMILY_MARES_PUCK, 7, DC_TRANSPORT_SERIAL, NULL}, + {"Mares", "Puck Air", DC_FAMILY_MARES_PUCK, 19, DC_TRANSPORT_SERIAL, NULL}, + {"Mares", "Nemo Air", DC_FAMILY_MARES_PUCK, 4, DC_TRANSPORT_SERIAL, NULL}, + {"Mares", "Nemo Wide", DC_FAMILY_MARES_PUCK, 1, DC_TRANSPORT_SERIAL, NULL}, /* Mares Darwin */ - {"Mares", "Darwin", DC_FAMILY_MARES_DARWIN , 0, NULL}, - {"Mares", "M1", DC_FAMILY_MARES_DARWIN , 0, NULL}, - {"Mares", "M2", DC_FAMILY_MARES_DARWIN , 0, NULL}, - {"Mares", "Darwin Air", DC_FAMILY_MARES_DARWIN , 1, NULL}, - {"Mares", "Airlab", DC_FAMILY_MARES_DARWIN , 1, NULL}, + {"Mares", "Darwin", DC_FAMILY_MARES_DARWIN , 0, DC_TRANSPORT_SERIAL, NULL}, + {"Mares", "M1", DC_FAMILY_MARES_DARWIN , 0, DC_TRANSPORT_SERIAL, NULL}, + {"Mares", "M2", DC_FAMILY_MARES_DARWIN , 0, DC_TRANSPORT_SERIAL, NULL}, + {"Mares", "Darwin Air", DC_FAMILY_MARES_DARWIN , 1, DC_TRANSPORT_SERIAL, NULL}, + {"Mares", "Airlab", DC_FAMILY_MARES_DARWIN , 1, DC_TRANSPORT_SERIAL, NULL}, /* Mares Icon HD */ - {"Mares", "Matrix", DC_FAMILY_MARES_ICONHD , 0x0F, NULL}, - {"Mares", "Smart", DC_FAMILY_MARES_ICONHD , 0x000010, NULL}, - {"Mares", "Smart Apnea", DC_FAMILY_MARES_ICONHD , 0x010010, NULL}, - {"Mares", "Icon HD", DC_FAMILY_MARES_ICONHD , 0x14, NULL}, - {"Mares", "Icon HD Net Ready", DC_FAMILY_MARES_ICONHD , 0x15, NULL}, - {"Mares", "Puck Pro", DC_FAMILY_MARES_ICONHD , 0x18, NULL}, - {"Mares", "Nemo Wide 2", DC_FAMILY_MARES_ICONHD , 0x19, NULL}, - {"Mares", "Puck 2", DC_FAMILY_MARES_ICONHD , 0x1F, NULL}, - {"Mares", "Quad Air", DC_FAMILY_MARES_ICONHD , 0x23, NULL}, - {"Mares", "Quad", DC_FAMILY_MARES_ICONHD , 0x29, NULL}, + {"Mares", "Matrix", DC_FAMILY_MARES_ICONHD , 0x0F, DC_TRANSPORT_SERIAL, NULL}, + {"Mares", "Smart", DC_FAMILY_MARES_ICONHD , 0x000010, DC_TRANSPORT_SERIAL, NULL}, + {"Mares", "Smart Apnea", DC_FAMILY_MARES_ICONHD , 0x010010, DC_TRANSPORT_SERIAL, NULL}, + {"Mares", "Icon HD", DC_FAMILY_MARES_ICONHD , 0x14, DC_TRANSPORT_SERIAL, NULL}, + {"Mares", "Icon HD Net Ready", DC_FAMILY_MARES_ICONHD , 0x15, DC_TRANSPORT_SERIAL, NULL}, + {"Mares", "Puck Pro", DC_FAMILY_MARES_ICONHD , 0x18, DC_TRANSPORT_SERIAL, NULL}, + {"Mares", "Nemo Wide 2", DC_FAMILY_MARES_ICONHD , 0x19, DC_TRANSPORT_SERIAL, NULL}, + {"Mares", "Puck 2", DC_FAMILY_MARES_ICONHD , 0x1F, DC_TRANSPORT_SERIAL, NULL}, + {"Mares", "Quad Air", DC_FAMILY_MARES_ICONHD , 0x23, DC_TRANSPORT_SERIAL, NULL}, + {"Mares", "Quad", DC_FAMILY_MARES_ICONHD , 0x29, DC_TRANSPORT_SERIAL, NULL}, /* Heinrichs Weikamp */ - {"Heinrichs Weikamp", "OSTC", DC_FAMILY_HW_OSTC, 0, NULL}, - {"Heinrichs Weikamp", "OSTC Mk2", DC_FAMILY_HW_OSTC, 1, NULL}, - {"Heinrichs Weikamp", "OSTC 2N", DC_FAMILY_HW_OSTC, 2, NULL}, - {"Heinrichs Weikamp", "OSTC 2C", DC_FAMILY_HW_OSTC, 3, NULL}, - {"Heinrichs Weikamp", "Frog", DC_FAMILY_HW_FROG, 0, dc_filter_hw}, - {"Heinrichs Weikamp", "OSTC 2", DC_FAMILY_HW_OSTC3, 0x11, dc_filter_hw}, - {"Heinrichs Weikamp", "OSTC 2", DC_FAMILY_HW_OSTC3, 0x13, dc_filter_hw}, - {"Heinrichs Weikamp", "OSTC 2", DC_FAMILY_HW_OSTC3, 0x1B, dc_filter_hw}, - {"Heinrichs Weikamp", "OSTC 3", DC_FAMILY_HW_OSTC3, 0x0A, dc_filter_hw}, - {"Heinrichs Weikamp", "OSTC Plus", DC_FAMILY_HW_OSTC3, 0x13, dc_filter_hw}, - {"Heinrichs Weikamp", "OSTC Plus", DC_FAMILY_HW_OSTC3, 0x1A, dc_filter_hw}, - {"Heinrichs Weikamp", "OSTC 4", DC_FAMILY_HW_OSTC3, 0x3B, dc_filter_hw}, - {"Heinrichs Weikamp", "OSTC cR", DC_FAMILY_HW_OSTC3, 0x05, dc_filter_hw}, - {"Heinrichs Weikamp", "OSTC cR", DC_FAMILY_HW_OSTC3, 0x07, dc_filter_hw}, - {"Heinrichs Weikamp", "OSTC Sport", DC_FAMILY_HW_OSTC3, 0x12, dc_filter_hw}, - {"Heinrichs Weikamp", "OSTC Sport", DC_FAMILY_HW_OSTC3, 0x13, dc_filter_hw}, - {"Heinrichs Weikamp", "OSTC 2 TR", DC_FAMILY_HW_OSTC3, 0x33, dc_filter_hw}, + {"Heinrichs Weikamp", "OSTC", DC_FAMILY_HW_OSTC, 0, DC_TRANSPORT_SERIAL, NULL}, + {"Heinrichs Weikamp", "OSTC Mk2", DC_FAMILY_HW_OSTC, 1, DC_TRANSPORT_SERIAL, NULL}, + {"Heinrichs Weikamp", "OSTC 2N", DC_FAMILY_HW_OSTC, 2, DC_TRANSPORT_SERIAL, NULL}, + {"Heinrichs Weikamp", "OSTC 2C", DC_FAMILY_HW_OSTC, 3, DC_TRANSPORT_SERIAL, NULL}, + {"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_TRANSPORT_SERIAL | DC_TRANSPORT_BLUETOOTH, 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_TRANSPORT_SERIAL | DC_TRANSPORT_BLUETOOTH, 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_TRANSPORT_SERIAL | DC_TRANSPORT_BLUETOOTH, 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_TRANSPORT_SERIAL | DC_TRANSPORT_BLUETOOTH, 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_TRANSPORT_SERIAL, 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_TRANSPORT_SERIAL | DC_TRANSPORT_BLUETOOTH, dc_filter_hw}, + {"Heinrichs Weikamp", "OSTC 2 TR", DC_FAMILY_HW_OSTC3, 0x33, DC_TRANSPORT_SERIAL | DC_TRANSPORT_BLUETOOTH, dc_filter_hw}, /* Cressi Edy */ - {"Tusa", "IQ-700", DC_FAMILY_CRESSI_EDY, 0x05, NULL}, - {"Cressi", "Edy", DC_FAMILY_CRESSI_EDY, 0x08, NULL}, + {"Tusa", "IQ-700", DC_FAMILY_CRESSI_EDY, 0x05, DC_TRANSPORT_SERIAL, NULL}, + {"Cressi", "Edy", DC_FAMILY_CRESSI_EDY, 0x08, DC_TRANSPORT_SERIAL, NULL}, /* Cressi Leonardo */ - {"Cressi", "Leonardo", DC_FAMILY_CRESSI_LEONARDO, 1, NULL}, - {"Cressi", "Giotto", DC_FAMILY_CRESSI_LEONARDO, 4, NULL}, - {"Cressi", "Newton", DC_FAMILY_CRESSI_LEONARDO, 5, NULL}, - {"Cressi", "Drake", DC_FAMILY_CRESSI_LEONARDO, 6, NULL}, + {"Cressi", "Leonardo", DC_FAMILY_CRESSI_LEONARDO, 1, DC_TRANSPORT_SERIAL, NULL}, + {"Cressi", "Giotto", DC_FAMILY_CRESSI_LEONARDO, 4, DC_TRANSPORT_SERIAL, NULL}, + {"Cressi", "Newton", DC_FAMILY_CRESSI_LEONARDO, 5, DC_TRANSPORT_SERIAL, NULL}, + {"Cressi", "Drake", DC_FAMILY_CRESSI_LEONARDO, 6, DC_TRANSPORT_SERIAL, NULL}, /* Zeagle N2iTiON3 */ - {"Zeagle", "N2iTiON3", DC_FAMILY_ZEAGLE_N2ITION3, 0, NULL}, - {"Apeks", "Quantum X", DC_FAMILY_ZEAGLE_N2ITION3, 0, NULL}, - {"Dive Rite", "NiTek Trio", DC_FAMILY_ZEAGLE_N2ITION3, 0, NULL}, - {"Scubapro", "XTender 5", 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, DC_TRANSPORT_SERIAL, NULL}, + {"Dive Rite", "NiTek Trio", DC_FAMILY_ZEAGLE_N2ITION3, 0, DC_TRANSPORT_SERIAL, NULL}, + {"Scubapro", "XTender 5", DC_FAMILY_ZEAGLE_N2ITION3, 0, DC_TRANSPORT_SERIAL, NULL}, /* Atomic Aquatics Cobalt */ -#ifdef HAVE_LIBUSB - {"Atomic Aquatics", "Cobalt", DC_FAMILY_ATOMICS_COBALT, 0, NULL}, - {"Atomic Aquatics", "Cobalt 2", DC_FAMILY_ATOMICS_COBALT, 2, NULL}, -#endif + {"Atomic Aquatics", "Cobalt", DC_FAMILY_ATOMICS_COBALT, 0, DC_TRANSPORT_USB, NULL}, + {"Atomic Aquatics", "Cobalt 2", DC_FAMILY_ATOMICS_COBALT, 2, DC_TRANSPORT_USB, NULL}, /* 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", DC_FAMILY_SHEARWATER_PETREL, 3, dc_filter_shearwater}, - {"Shearwater", "Petrel 2", DC_FAMILY_SHEARWATER_PETREL, 3, dc_filter_shearwater}, - {"Shearwater", "Nerd", DC_FAMILY_SHEARWATER_PETREL, 4, dc_filter_shearwater}, - {"Shearwater", "Perdix", DC_FAMILY_SHEARWATER_PETREL, 5, dc_filter_shearwater}, - {"Shearwater", "Perdix AI", DC_FAMILY_SHEARWATER_PETREL, 6, dc_filter_shearwater}, - {"Shearwater", "Nerd 2", DC_FAMILY_SHEARWATER_PETREL, 7, 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_TRANSPORT_SERIAL | DC_TRANSPORT_BLUETOOTH, 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_TRANSPORT_SERIAL | DC_TRANSPORT_BLUETOOTH, 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_TRANSPORT_NONE, dc_filter_shearwater}, /* 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", DC_FAMILY_CITIZEN_AQUALAND, 0, NULL}, + {"Citizen", "Hyper Aqualand", DC_FAMILY_CITIZEN_AQUALAND, 0, DC_TRANSPORT_SERIAL, NULL}, /* DiveSystem/Ratio iDive */ - {"DiveSystem", "Orca", DC_FAMILY_DIVESYSTEM_IDIVE, 0x02, NULL}, - {"DiveSystem", "iDive Pro", DC_FAMILY_DIVESYSTEM_IDIVE, 0x03, NULL}, - {"DiveSystem", "iDive DAN", DC_FAMILY_DIVESYSTEM_IDIVE, 0x04, NULL}, - {"DiveSystem", "iDive Tech", DC_FAMILY_DIVESYSTEM_IDIVE, 0x05, NULL}, - {"DiveSystem", "iDive Reb", DC_FAMILY_DIVESYSTEM_IDIVE, 0x06, NULL}, - {"DiveSystem", "iDive Stealth", DC_FAMILY_DIVESYSTEM_IDIVE, 0x07, NULL}, - {"DiveSystem", "iDive Free", DC_FAMILY_DIVESYSTEM_IDIVE, 0x08, NULL}, - {"DiveSystem", "iDive Easy", DC_FAMILY_DIVESYSTEM_IDIVE, 0x09, NULL}, - {"DiveSystem", "iDive X3M", DC_FAMILY_DIVESYSTEM_IDIVE, 0x0A, NULL}, - {"DiveSystem", "iDive Deep", DC_FAMILY_DIVESYSTEM_IDIVE, 0x0B, NULL}, - {"Ratio", "iX3M Easy", DC_FAMILY_DIVESYSTEM_IDIVE, 0x22, NULL}, - {"Ratio", "iX3M Deep", DC_FAMILY_DIVESYSTEM_IDIVE, 0x23, NULL}, - {"Ratio", "iX3M Tech+", DC_FAMILY_DIVESYSTEM_IDIVE, 0x24, NULL}, - {"Ratio", "iX3M Reb", DC_FAMILY_DIVESYSTEM_IDIVE, 0x25, NULL}, - {"Ratio", "iX3M Pro Easy", DC_FAMILY_DIVESYSTEM_IDIVE, 0x32, NULL}, - {"Ratio", "iX3M Pro Deep", DC_FAMILY_DIVESYSTEM_IDIVE, 0x34, NULL}, - {"Ratio", "iX3M Pro Tech+",DC_FAMILY_DIVESYSTEM_IDIVE, 0x35, NULL}, - {"Ratio", "iDive Free", DC_FAMILY_DIVESYSTEM_IDIVE, 0x40, NULL}, - {"Ratio", "iDive Easy", DC_FAMILY_DIVESYSTEM_IDIVE, 0x42, NULL}, - {"Ratio", "iDive Deep", DC_FAMILY_DIVESYSTEM_IDIVE, 0x44, NULL}, - {"Ratio", "iDive Tech+", DC_FAMILY_DIVESYSTEM_IDIVE, 0x45, NULL}, - {"Seac", "Jack", DC_FAMILY_DIVESYSTEM_IDIVE, 0x1000, NULL}, + {"DiveSystem", "Orca", DC_FAMILY_DIVESYSTEM_IDIVE, 0x02, DC_TRANSPORT_SERIAL, NULL}, + {"DiveSystem", "iDive Pro", DC_FAMILY_DIVESYSTEM_IDIVE, 0x03, DC_TRANSPORT_SERIAL, NULL}, + {"DiveSystem", "iDive DAN", DC_FAMILY_DIVESYSTEM_IDIVE, 0x04, DC_TRANSPORT_SERIAL, NULL}, + {"DiveSystem", "iDive Tech", DC_FAMILY_DIVESYSTEM_IDIVE, 0x05, DC_TRANSPORT_SERIAL, NULL}, + {"DiveSystem", "iDive Reb", DC_FAMILY_DIVESYSTEM_IDIVE, 0x06, DC_TRANSPORT_SERIAL, NULL}, + {"DiveSystem", "iDive Stealth", DC_FAMILY_DIVESYSTEM_IDIVE, 0x07, DC_TRANSPORT_SERIAL, NULL}, + {"DiveSystem", "iDive Free", DC_FAMILY_DIVESYSTEM_IDIVE, 0x08, DC_TRANSPORT_SERIAL, NULL}, + {"DiveSystem", "iDive Easy", DC_FAMILY_DIVESYSTEM_IDIVE, 0x09, DC_TRANSPORT_SERIAL, NULL}, + {"DiveSystem", "iDive X3M", DC_FAMILY_DIVESYSTEM_IDIVE, 0x0A, DC_TRANSPORT_SERIAL, NULL}, + {"DiveSystem", "iDive Deep", DC_FAMILY_DIVESYSTEM_IDIVE, 0x0B, DC_TRANSPORT_SERIAL, NULL}, + {"Ratio", "iX3M Easy", DC_FAMILY_DIVESYSTEM_IDIVE, 0x22, DC_TRANSPORT_SERIAL, NULL}, + {"Ratio", "iX3M Deep", DC_FAMILY_DIVESYSTEM_IDIVE, 0x23, DC_TRANSPORT_SERIAL, NULL}, + {"Ratio", "iX3M Tech+", DC_FAMILY_DIVESYSTEM_IDIVE, 0x24, DC_TRANSPORT_SERIAL, NULL}, + {"Ratio", "iX3M Reb", DC_FAMILY_DIVESYSTEM_IDIVE, 0x25, DC_TRANSPORT_SERIAL, NULL}, + {"Ratio", "iX3M Pro Easy", DC_FAMILY_DIVESYSTEM_IDIVE, 0x32, DC_TRANSPORT_SERIAL, NULL}, + {"Ratio", "iX3M Pro Deep", DC_FAMILY_DIVESYSTEM_IDIVE, 0x34, DC_TRANSPORT_SERIAL, NULL}, + {"Ratio", "iX3M Pro Tech+",DC_FAMILY_DIVESYSTEM_IDIVE, 0x35, DC_TRANSPORT_SERIAL, NULL}, + {"Ratio", "iDive Free", DC_FAMILY_DIVESYSTEM_IDIVE, 0x40, DC_TRANSPORT_SERIAL, NULL}, + {"Ratio", "iDive Easy", DC_FAMILY_DIVESYSTEM_IDIVE, 0x42, DC_TRANSPORT_SERIAL, NULL}, + {"Ratio", "iDive Deep", DC_FAMILY_DIVESYSTEM_IDIVE, 0x44, DC_TRANSPORT_SERIAL, NULL}, + {"Ratio", "iDive Tech+", DC_FAMILY_DIVESYSTEM_IDIVE, 0x45, DC_TRANSPORT_SERIAL, NULL}, + {"Seac", "Jack", DC_FAMILY_DIVESYSTEM_IDIVE, 0x1000, DC_TRANSPORT_SERIAL, NULL}, /* Cochran Commander */ - {"Cochran", "Commander TM", DC_FAMILY_COCHRAN_COMMANDER, 0, NULL}, - {"Cochran", "Commander I", DC_FAMILY_COCHRAN_COMMANDER, 1, NULL}, - {"Cochran", "Commander II", DC_FAMILY_COCHRAN_COMMANDER, 2, NULL}, - {"Cochran", "EMC-14", DC_FAMILY_COCHRAN_COMMANDER, 3, NULL}, - {"Cochran", "EMC-16", DC_FAMILY_COCHRAN_COMMANDER, 4, NULL}, - {"Cochran", "EMC-20H", DC_FAMILY_COCHRAN_COMMANDER, 5, NULL}, + {"Cochran", "Commander TM", DC_FAMILY_COCHRAN_COMMANDER, 0, DC_TRANSPORT_SERIAL, NULL}, + {"Cochran", "Commander I", DC_FAMILY_COCHRAN_COMMANDER, 1, DC_TRANSPORT_SERIAL, NULL}, + {"Cochran", "Commander II", DC_FAMILY_COCHRAN_COMMANDER, 2, DC_TRANSPORT_SERIAL, NULL}, + {"Cochran", "EMC-14", DC_FAMILY_COCHRAN_COMMANDER, 3, DC_TRANSPORT_SERIAL, NULL}, + {"Cochran", "EMC-16", DC_FAMILY_COCHRAN_COMMANDER, 4, DC_TRANSPORT_SERIAL, NULL}, + {"Cochran", "EMC-20H", DC_FAMILY_COCHRAN_COMMANDER, 5, DC_TRANSPORT_SERIAL, NULL}, }; static int @@ -530,22 +503,13 @@ dc_descriptor_get_model (dc_descriptor_t *descriptor) return descriptor->model; } -dc_transport_t -dc_descriptor_get_transport (dc_descriptor_t *descriptor) +unsigned int +dc_descriptor_get_transports (dc_descriptor_t *descriptor) { if (descriptor == NULL) return DC_TRANSPORT_NONE; - if (descriptor->type == DC_FAMILY_ATOMICS_COBALT) - 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; + return descriptor->transports; } dc_filter_t diff --git a/src/device.c b/src/device.c index 7c3da19..885fd10 100644 --- a/src/device.c +++ b/src/device.c @@ -100,7 +100,7 @@ dc_device_deallocate (dc_device_t *device) } 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_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)) { case DC_FAMILY_SUUNTO_SOLUTION: - rc = suunto_solution_device_open (&device, context, name); + rc = suunto_solution_device_open (&device, context, iostream); break; case DC_FAMILY_SUUNTO_EON: - rc = suunto_eon_device_open (&device, context, name); + rc = suunto_eon_device_open (&device, context, iostream); break; case DC_FAMILY_SUUNTO_VYPER: - rc = suunto_vyper_device_open (&device, context, name); + rc = suunto_vyper_device_open (&device, context, iostream); break; case DC_FAMILY_SUUNTO_VYPER2: - rc = suunto_vyper2_device_open (&device, context, name); + rc = suunto_vyper2_device_open (&device, context, iostream); break; 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; 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; case DC_FAMILY_UWATEC_ALADIN: - rc = uwatec_aladin_device_open (&device, context, name); + rc = uwatec_aladin_device_open (&device, context, iostream); break; case DC_FAMILY_UWATEC_MEMOMOUSE: - rc = uwatec_memomouse_device_open (&device, context, name); + rc = uwatec_memomouse_device_open (&device, context, iostream); break; case DC_FAMILY_UWATEC_SMART: - rc = uwatec_smart_device_open (&device, context); + rc = uwatec_smart_device_open (&device, context, iostream); break; case DC_FAMILY_UWATEC_MERIDIAN: - rc = uwatec_meridian_device_open (&device, context, name); + rc = uwatec_meridian_device_open (&device, context, iostream); break; 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; case DC_FAMILY_REEFNET_SENSUS: - rc = reefnet_sensus_device_open (&device, context, name); + rc = reefnet_sensus_device_open (&device, context, iostream); break; case DC_FAMILY_REEFNET_SENSUSPRO: - rc = reefnet_sensuspro_device_open (&device, context, name); + rc = reefnet_sensuspro_device_open (&device, context, iostream); break; case DC_FAMILY_REEFNET_SENSUSULTRA: - rc = reefnet_sensusultra_device_open (&device, context, name); + rc = reefnet_sensusultra_device_open (&device, context, iostream); break; 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; case DC_FAMILY_OCEANIC_VEO250: - rc = oceanic_veo250_device_open (&device, context, name); + rc = oceanic_veo250_device_open (&device, context, iostream); break; 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; case DC_FAMILY_MARES_NEMO: - rc = mares_nemo_device_open (&device, context, name); + rc = mares_nemo_device_open (&device, context, iostream); break; case DC_FAMILY_MARES_PUCK: - rc = mares_puck_device_open (&device, context, name); + rc = mares_puck_device_open (&device, context, iostream); break; 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; case DC_FAMILY_MARES_ICONHD: - rc = mares_iconhd_device_open (&device, context, name); + rc = mares_iconhd_device_open (&device, context, iostream); break; case DC_FAMILY_HW_OSTC: - rc = hw_ostc_device_open (&device, context, name); + rc = hw_ostc_device_open (&device, context, iostream); break; case DC_FAMILY_HW_FROG: - rc = hw_frog_device_open (&device, context, name); + rc = hw_frog_device_open (&device, context, iostream); break; case DC_FAMILY_HW_OSTC3: - rc = hw_ostc3_device_open (&device, context, name); + rc = hw_ostc3_device_open (&device, context, iostream); break; case DC_FAMILY_CRESSI_EDY: - rc = cressi_edy_device_open (&device, context, name); + rc = cressi_edy_device_open (&device, context, iostream); break; case DC_FAMILY_CRESSI_LEONARDO: - rc = cressi_leonardo_device_open (&device, context, name); + rc = cressi_leonardo_device_open (&device, context, iostream); break; case DC_FAMILY_ZEAGLE_N2ITION3: - rc = zeagle_n2ition3_device_open (&device, context, name); + rc = zeagle_n2ition3_device_open (&device, context, iostream); break; case DC_FAMILY_ATOMICS_COBALT: rc = atomics_cobalt_device_open (&device, context); break; case DC_FAMILY_SHEARWATER_PREDATOR: - rc = shearwater_predator_device_open (&device, context, name); + rc = shearwater_predator_device_open (&device, context, iostream); break; case DC_FAMILY_SHEARWATER_PETREL: - rc = shearwater_petrel_device_open (&device, context, name); + rc = shearwater_petrel_device_open (&device, context, iostream); break; case DC_FAMILY_DIVERITE_NITEKQ: - rc = diverite_nitekq_device_open (&device, context, name); + rc = diverite_nitekq_device_open (&device, context, iostream); break; case DC_FAMILY_CITIZEN_AQUALAND: - rc = citizen_aqualand_device_open (&device, context, name); + rc = citizen_aqualand_device_open (&device, context, iostream); break; 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; case DC_FAMILY_COCHRAN_COMMANDER: - rc = cochran_commander_device_open (&device, context, name); + rc = cochran_commander_device_open (&device, context, iostream); break; default: return DC_STATUS_INVALIDARGS; diff --git a/src/diverite_nitekq.c b/src/diverite_nitekq.c index 6fc38b5..676fb90 100644 --- a/src/diverite_nitekq.c +++ b/src/diverite_nitekq.c @@ -27,7 +27,6 @@ #include "context-private.h" #include "device-private.h" #include "checksum.h" -#include "serial.h" #include "array.h" #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 -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; 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. - device->iostream = NULL; + device->iostream = iostream; 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). status = dc_iostream_configure (device->iostream, 9600, 8, DC_PARITY_NONE, DC_STOPBITS_ONE, DC_FLOWCONTROL_NONE); if (status != DC_STATUS_SUCCESS) { ERROR (context, "Failed to set the terminal attributes."); - goto error_close; + goto error_free; } // Set the timeout for receiving data (1000ms). status = dc_iostream_set_timeout (device->iostream, 1000); if (status != DC_STATUS_SUCCESS) { ERROR (context, "Failed to set the timeout."); - goto error_close; + goto error_free; } // 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); if (status != DC_STATUS_SUCCESS) { ERROR (context, "Failed to handshake."); - goto error_close; + goto error_free; } *out = (dc_device_t*) device; return DC_STATUS_SUCCESS; -error_close: - dc_iostream_close (device->iostream); error_free: dc_device_deallocate ((dc_device_t *) device); return status; @@ -224,12 +214,6 @@ diverite_nitekq_device_close (dc_device_t *abstract) 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; } diff --git a/src/diverite_nitekq.h b/src/diverite_nitekq.h index c8987e2..e016cab 100644 --- a/src/diverite_nitekq.h +++ b/src/diverite_nitekq.h @@ -23,6 +23,7 @@ #define DIVERITE_NITEKQ_H #include +#include #include #include @@ -31,7 +32,7 @@ extern "C" { #endif /* __cplusplus */ 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 diverite_nitekq_parser_create (dc_parser_t **parser, dc_context_t *context); diff --git a/src/divesystem_idive.c b/src/divesystem_idive.c index f2976b1..790e71a 100644 --- a/src/divesystem_idive.c +++ b/src/divesystem_idive.c @@ -25,7 +25,6 @@ #include "divesystem_idive.h" #include "context-private.h" #include "device-private.h" -#include "serial.h" #include "checksum.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_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 = { sizeof(divesystem_idive_device_t), @@ -87,7 +85,7 @@ static const dc_device_vtable_t divesystem_idive_device_vtable = { NULL, /* dump */ divesystem_idive_device_foreach, /* foreach */ NULL, /* timesync */ - divesystem_idive_device_close /* close */ + NULL /* close */ }; static const divesystem_idive_commands_t idive = { @@ -115,7 +113,7 @@ static const divesystem_idive_commands_t ix3m_apos4 = { }; 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; 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. - device->iostream = NULL; + device->iostream = iostream; memset (device->fingerprint, 0, sizeof (device->fingerprint)); 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). status = dc_iostream_configure (device->iostream, 115200, 8, DC_PARITY_NONE, DC_STOPBITS_ONE, DC_FLOWCONTROL_NONE); if (status != DC_STATUS_SUCCESS) { ERROR (context, "Failed to set the terminal attributes."); - goto error_close; + goto error_free; } // Set the timeout for receiving data (1000ms). status = dc_iostream_set_timeout (device->iostream, 1000); if (status != DC_STATUS_SUCCESS) { ERROR (context, "Failed to set the timeout."); - goto error_close; + goto error_free; } // 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; -error_close: - dc_iostream_close (device->iostream); error_free: dc_device_deallocate ((dc_device_t *) device); 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 divesystem_idive_device_set_fingerprint (dc_device_t *abstract, const unsigned char data[], unsigned int size) { diff --git a/src/divesystem_idive.h b/src/divesystem_idive.h index 20ed729..8c79866 100644 --- a/src/divesystem_idive.h +++ b/src/divesystem_idive.h @@ -23,6 +23,7 @@ #define DIVESYSTEM_IDIVE_H #include +#include #include #include @@ -31,7 +32,7 @@ extern "C" { #endif /* __cplusplus */ 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 divesystem_idive_parser_create (dc_parser_t **parser, dc_context_t *context, unsigned int model); diff --git a/src/hw_frog.c b/src/hw_frog.c index 7953b18..74fc170 100644 --- a/src/hw_frog.c +++ b/src/hw_frog.c @@ -25,7 +25,6 @@ #include "hw_frog.h" #include "context-private.h" #include "device-private.h" -#include "serial.h" #include "checksum.h" #include "ringbuffer.h" #include "array.h" @@ -199,7 +198,7 @@ hw_frog_transfer (hw_frog_device_t *device, 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; 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. - device->iostream = NULL; + device->iostream = iostream; 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). status = dc_iostream_configure (device->iostream, 115200, 8, DC_PARITY_NONE, DC_STOPBITS_ONE, DC_FLOWCONTROL_NONE); if (status != DC_STATUS_SUCCESS) { ERROR (context, "Failed to set the terminal attributes."); - goto error_close; + goto error_free; } // Set the timeout for receiving data (3000ms). status = dc_iostream_set_timeout (device->iostream, 3000); if (status != DC_STATUS_SUCCESS) { ERROR (context, "Failed to set the timeout."); - goto error_close; + goto error_free; } // 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); if (status != DC_STATUS_SUCCESS) { ERROR (context, "Failed to send the command."); - goto error_close; + goto error_free; } *out = (dc_device_t *) device; return DC_STATUS_SUCCESS; -error_close: - dc_iostream_close (device->iostream); error_free: dc_device_deallocate ((dc_device_t *) device); return status; @@ -276,12 +266,6 @@ hw_frog_device_close (dc_device_t *abstract) 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; } diff --git a/src/hw_frog.h b/src/hw_frog.h index 260e80d..74cf5af 100644 --- a/src/hw_frog.h +++ b/src/hw_frog.h @@ -23,6 +23,7 @@ #define HW_FROG_H #include +#include #include #include #include @@ -32,7 +33,7 @@ extern "C" { #endif /* __cplusplus */ 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 } diff --git a/src/hw_ostc.c b/src/hw_ostc.c index c47af16..cb64818 100644 --- a/src/hw_ostc.c +++ b/src/hw_ostc.c @@ -25,7 +25,6 @@ #include "hw_ostc.h" #include "context-private.h" #include "device-private.h" -#include "serial.h" #include "checksum.h" #include "array.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_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_close (dc_device_t *abstract); static const dc_device_vtable_t hw_ostc_device_vtable = { 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_foreach, /* foreach */ hw_ostc_device_timesync, /* timesync */ - hw_ostc_device_close /* close */ + NULL /* close */ }; 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 -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; 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. - device->iostream = NULL; + device->iostream = iostream; 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). status = dc_iostream_configure (device->iostream, 115200, 8, DC_PARITY_NONE, DC_STOPBITS_ONE, DC_FLOWCONTROL_NONE); if (status != DC_STATUS_SUCCESS) { ERROR (context, "Failed to set the terminal attributes."); - goto error_close; + goto error_free; } // Set the timeout for receiving data. status = dc_iostream_set_timeout (device->iostream, 4000); if (status != DC_STATUS_SUCCESS) { ERROR (context, "Failed to set the timeout."); - goto error_close; + goto error_free; } // 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; -error_close: - dc_iostream_close (device->iostream); error_free: dc_device_deallocate ((dc_device_t *) device); 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 hw_ostc_device_set_fingerprint (dc_device_t *abstract, const unsigned char data[], unsigned int size) { diff --git a/src/hw_ostc.h b/src/hw_ostc.h index 3f54a7b..a0ce743 100644 --- a/src/hw_ostc.h +++ b/src/hw_ostc.h @@ -23,6 +23,7 @@ #define HW_OSTC_H #include +#include #include #include #include @@ -32,7 +33,7 @@ extern "C" { #endif /* __cplusplus */ 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 hw_ostc_parser_create (dc_parser_t **parser, dc_context_t *context, unsigned int hwos); diff --git a/src/hw_ostc3.c b/src/hw_ostc3.c index 9a6c731..dec0a44 100644 --- a/src/hw_ostc3.c +++ b/src/hw_ostc3.c @@ -27,7 +27,6 @@ #include "hw_ostc3.h" #include "context-private.h" #include "device-private.h" -#include "serial.h" #include "array.h" #include "aes.h" #include "platform.h" @@ -316,7 +315,7 @@ hw_ostc3_transfer (hw_ostc3_device_t *device, 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; 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. - device->iostream = NULL; + device->iostream = iostream; device->hardware = INVALID; device->feature = 0; device->model = 0; 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). status = dc_iostream_configure (device->iostream, 115200, 8, DC_PARITY_NONE, DC_STOPBITS_ONE, DC_FLOWCONTROL_NONE); if (status != DC_STATUS_SUCCESS) { ERROR (context, "Failed to set the terminal attributes."); - goto error_close; + goto error_free; } // Set the timeout for receiving data (3000ms). status = dc_iostream_set_timeout (device->iostream, 3000); if (status != DC_STATUS_SUCCESS) { ERROR (context, "Failed to set the timeout."); - goto error_close; + goto error_free; } // 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; -error_close: - dc_iostream_close (device->iostream); error_free: dc_device_deallocate ((dc_device_t *) device); 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; } diff --git a/src/hw_ostc3.h b/src/hw_ostc3.h index eec35b7..92cf277 100644 --- a/src/hw_ostc3.h +++ b/src/hw_ostc3.h @@ -23,6 +23,7 @@ #define HW_OSTC3_H #include +#include #include #include #include @@ -32,7 +33,7 @@ extern "C" { #endif /* __cplusplus */ 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 hw_ostc3_parser_create (dc_parser_t **out, dc_context_t *context, unsigned int model); diff --git a/src/iostream-private.h b/src/iostream-private.h index b9bd4f1..f9c0883 100644 --- a/src/iostream-private.h +++ b/src/iostream-private.h @@ -35,6 +35,7 @@ typedef struct dc_iostream_vtable_t dc_iostream_vtable_t; struct dc_iostream_t { const dc_iostream_vtable_t *vtable; dc_context_t *context; + dc_transport_t transport; }; struct dc_iostream_vtable_t { @@ -70,7 +71,7 @@ struct dc_iostream_vtable_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 dc_iostream_deallocate (dc_iostream_t *iostream); diff --git a/src/iostream.c b/src/iostream.c index c1e3017..9681d02 100644 --- a/src/iostream.c +++ b/src/iostream.c @@ -27,7 +27,7 @@ #include "context-private.h" 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; @@ -44,6 +44,7 @@ dc_iostream_allocate (dc_context_t *context, const dc_iostream_vtable_t *vtable) // Initialize the base class. iostream->vtable = vtable; iostream->context = context; + iostream->transport = transport; return iostream; } @@ -63,6 +64,15 @@ dc_iostream_isinstance (dc_iostream_t *iostream, const dc_iostream_vtable_t *vta 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_iostream_set_timeout (dc_iostream_t *iostream, int timeout) { diff --git a/src/irda.c b/src/irda.c index d1aecfb..a5cf803 100644 --- a/src/irda.c +++ b/src/irda.c @@ -42,7 +42,7 @@ #endif #endif -#include "irda.h" +#include #include "common-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); // 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) { SYSERROR (context, S_ENOMEM); return DC_STATUS_NOMEMORY; diff --git a/src/libdivecomputer.symbols b/src/libdivecomputer.symbols index a0c3724..2d7e7de 100644 --- a/src/libdivecomputer.symbols +++ b/src/libdivecomputer.symbols @@ -21,6 +21,7 @@ dc_context_new dc_context_free dc_context_set_loglevel dc_context_set_logfunc +dc_context_get_transports dc_iterator_next dc_iterator_free @@ -31,8 +32,9 @@ dc_descriptor_get_vendor dc_descriptor_get_product dc_descriptor_get_type dc_descriptor_get_model -dc_descriptor_get_transport +dc_descriptor_get_transports +dc_iostream_get_transport dc_iostream_set_timeout dc_iostream_set_latency dc_iostream_set_break @@ -48,6 +50,33 @@ dc_iostream_purge dc_iostream_sleep 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_new2 dc_parser_get_type diff --git a/src/mares_common.c b/src/mares_common.c index f476d8d..a890701 100644 --- a/src/mares_common.c +++ b/src/mares_common.c @@ -47,12 +47,12 @@ #define GAUGE 3 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); // Set the default values. - device->iostream = NULL; + device->iostream = iostream; device->echo = 0; device->delay = 0; } diff --git a/src/mares_common.h b/src/mares_common.h index 8cb58ca..000ea28 100644 --- a/src/mares_common.h +++ b/src/mares_common.h @@ -22,8 +22,9 @@ #ifndef MARES_COMMON_H #define MARES_COMMON_H +#include + #include "device-private.h" -#include "serial.h" #ifdef __cplusplus extern "C" { @@ -47,7 +48,7 @@ typedef struct mares_common_device_t { } mares_common_device_t; 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 mares_common_device_read (dc_device_t *abstract, unsigned int address, unsigned char data[], unsigned int size); diff --git a/src/mares_darwin.c b/src/mares_darwin.c index 0d5152d..92172f2 100644 --- a/src/mares_darwin.c +++ b/src/mares_darwin.c @@ -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_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_close (dc_device_t *abstract); static const dc_device_vtable_t mares_darwin_device_vtable = { 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_foreach, /* foreach */ NULL, /* timesync */ - mares_darwin_device_close /* close */ + NULL /* close */ }; 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); 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; 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. - mares_common_device_init (&device->base); + mares_common_device_init (&device->base, iostream); // Set the default values. 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 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). status = dc_iostream_configure (device->base.iostream, 9600, 8, DC_PARITY_NONE, DC_STOPBITS_ONE, DC_FLOWCONTROL_NONE); if (status != DC_STATUS_SUCCESS) { ERROR (context, "Failed to set the terminal attributes."); - goto error_close; + goto error_free; } // Set the timeout for receiving data (1000 ms). status = dc_iostream_set_timeout (device->base.iostream, 1000); if (status != DC_STATUS_SUCCESS) { ERROR (context, "Failed to set the timeout."); - goto error_close; + goto error_free; } // Set the DTR line. status = dc_iostream_set_dtr (device->base.iostream, 1); if (status != DC_STATUS_SUCCESS) { ERROR (context, "Failed to set the DTR line."); - goto error_close; + goto error_free; } // Set the RTS line. status = dc_iostream_set_rts (device->base.iostream, 1); if (status != DC_STATUS_SUCCESS) { ERROR (context, "Failed to set the RTS line."); - goto error_close; + goto error_free; } // 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; -error_close: - dc_iostream_close (device->base.iostream); error_free: dc_device_deallocate ((dc_device_t *) device); 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 mares_darwin_device_set_fingerprint (dc_device_t *abstract, const unsigned char data[], unsigned int size) diff --git a/src/mares_darwin.h b/src/mares_darwin.h index e7767ec..a902014 100644 --- a/src/mares_darwin.h +++ b/src/mares_darwin.h @@ -23,6 +23,7 @@ #define MARES_DARWIN_H #include +#include #include #include @@ -31,7 +32,7 @@ extern "C" { #endif /* __cplusplus */ 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 mares_darwin_parser_create (dc_parser_t **parser, dc_context_t *context, unsigned int model); diff --git a/src/mares_iconhd.c b/src/mares_iconhd.c index c9352e2..450245e 100644 --- a/src/mares_iconhd.c +++ b/src/mares_iconhd.c @@ -26,7 +26,6 @@ #include "mares_iconhd.h" #include "context-private.h" #include "device-private.h" -#include "serial.h" #include "array.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_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_close (dc_device_t *abstract); static const dc_device_vtable_t mares_iconhd_device_vtable = { 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_foreach, /* foreach */ NULL, /* timesync */ - mares_iconhd_device_close /* close */ + NULL /* close */ }; static const mares_iconhd_layout_t mares_iconhd_layout = { @@ -214,7 +212,7 @@ mares_iconhd_transfer (mares_iconhd_device_t *device, 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; 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. - device->iostream = NULL; + device->iostream = iostream; device->layout = NULL; memset (device->fingerprint, 0, sizeof (device->fingerprint)); memset (device->version, 0, sizeof (device->version)); device->model = 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). status = dc_iostream_configure (device->iostream, 115200, 8, DC_PARITY_EVEN, DC_STOPBITS_ONE, DC_FLOWCONTROL_NONE); if (status != DC_STATUS_SUCCESS) { ERROR (context, "Failed to set the terminal attributes."); - goto error_close; + goto error_free; } // Set the timeout for receiving data (1000 ms). status = dc_iostream_set_timeout (device->iostream, 1000); if (status != DC_STATUS_SUCCESS) { ERROR (context, "Failed to set the timeout."); - goto error_close; + goto error_free; } // Clear the DTR line. status = dc_iostream_set_dtr (device->iostream, 0); if (status != DC_STATUS_SUCCESS) { ERROR (context, "Failed to clear the DTR line."); - goto error_close; + goto error_free; } // Clear the RTS line. status = dc_iostream_set_rts (device->iostream, 0); if (status != DC_STATUS_SUCCESS) { ERROR (context, "Failed to clear the RTS line."); - goto error_close; + goto error_free; } // 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), device->version, sizeof (device->version)); if (status != DC_STATUS_SUCCESS) { - goto error_close; + goto error_free; } // 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; -error_close: - dc_iostream_close (device->iostream); error_free: dc_device_deallocate ((dc_device_t *) device); 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 mares_iconhd_device_set_fingerprint (dc_device_t *abstract, const unsigned char data[], unsigned int size) { diff --git a/src/mares_iconhd.h b/src/mares_iconhd.h index b762843..55a50d0 100644 --- a/src/mares_iconhd.h +++ b/src/mares_iconhd.h @@ -23,6 +23,7 @@ #define MARES_ICONHD_H #include +#include #include #include @@ -31,7 +32,7 @@ extern "C" { #endif /* __cplusplus */ 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 mares_iconhd_parser_create (dc_parser_t **parser, dc_context_t *context, unsigned int model); diff --git a/src/mares_nemo.c b/src/mares_nemo.c index a83b459..7529704 100644 --- a/src/mares_nemo.c +++ b/src/mares_nemo.c @@ -26,7 +26,6 @@ #include "mares_common.h" #include "context-private.h" #include "device-private.h" -#include "serial.h" #include "checksum.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_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_close (dc_device_t *abstract); static const dc_device_vtable_t mares_nemo_device_vtable = { 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_foreach, /* foreach */ NULL, /* timesync */ - mares_nemo_device_close /* close */ + NULL /* close */ }; 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 -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; 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. - device->iostream = NULL; + device->iostream = iostream; 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). status = dc_iostream_configure (device->iostream, 9600, 8, DC_PARITY_NONE, DC_STOPBITS_ONE, DC_FLOWCONTROL_NONE); if (status != DC_STATUS_SUCCESS) { ERROR (context, "Failed to set the terminal attributes."); - goto error_close; + goto error_free; } // Set the timeout for receiving data (1000 ms). status = dc_iostream_set_timeout (device->iostream, 1000); if (status != DC_STATUS_SUCCESS) { ERROR (context, "Failed to set the timeout."); - goto error_close; + goto error_free; } // Set the DTR line. status = dc_iostream_set_dtr (device->iostream, 1); if (status != DC_STATUS_SUCCESS) { ERROR (context, "Failed to set the DTR line."); - goto error_close; + goto error_free; } // Set the RTS line. status = dc_iostream_set_rts (device->iostream, 1); if (status != DC_STATUS_SUCCESS) { ERROR (context, "Failed to set the RTS line."); - goto error_close; + goto error_free; } // 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; -error_close: - dc_iostream_close (device->iostream); error_free: dc_device_deallocate ((dc_device_t *) device); 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 mares_nemo_device_set_fingerprint (dc_device_t *abstract, const unsigned char data[], unsigned int size) { diff --git a/src/mares_nemo.h b/src/mares_nemo.h index e25489b..c7a162b 100644 --- a/src/mares_nemo.h +++ b/src/mares_nemo.h @@ -23,6 +23,7 @@ #define MARES_NEMO_H #include +#include #include #include @@ -31,7 +32,7 @@ extern "C" { #endif /* __cplusplus */ 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 mares_nemo_parser_create (dc_parser_t **parser, dc_context_t *context, unsigned int model); diff --git a/src/mares_puck.c b/src/mares_puck.c index 6d921f0..614d886 100644 --- a/src/mares_puck.c +++ b/src/mares_puck.c @@ -27,7 +27,6 @@ #include "mares_common.h" #include "context-private.h" #include "device-private.h" -#include "serial.h" #include "checksum.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_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_close (dc_device_t *abstract); static const dc_device_vtable_t mares_puck_device_vtable = { 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_foreach, /* foreach */ NULL, /* timesync */ - mares_puck_device_close /* close */ + NULL /* close */ }; 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 -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; 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. - mares_common_device_init (&device->base); + mares_common_device_init (&device->base, iostream); // Set the default values. device->layout = NULL; 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). status = dc_iostream_configure (device->base.iostream, 38400, 8, DC_PARITY_NONE, DC_STOPBITS_ONE, DC_FLOWCONTROL_NONE); if (status != DC_STATUS_SUCCESS) { ERROR (context, "Failed to set the terminal attributes."); - goto error_close; + goto error_free; } // Set the timeout for receiving data (1000 ms). status = dc_iostream_set_timeout (device->base.iostream, 1000); if (status != DC_STATUS_SUCCESS) { ERROR (context, "Failed to set the timeout."); - goto error_close; + goto error_free; } // Clear the DTR line. status = dc_iostream_set_dtr (device->base.iostream, 0); if (status != DC_STATUS_SUCCESS) { ERROR (context, "Failed to clear the DTR line."); - goto error_close; + goto error_free; } // Clear the RTS line. status = dc_iostream_set_rts (device->base.iostream, 0); if (status != DC_STATUS_SUCCESS) { ERROR (context, "Failed to clear the RTS line."); - goto error_close; + goto error_free; } // 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}; status = mares_common_device_read ((dc_device_t *) device, 0, header, sizeof (header)); if (status != DC_STATUS_SUCCESS) { - goto error_close; + goto error_free; } // 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; -error_close: - dc_iostream_close (device->base.iostream); error_free: dc_device_deallocate ((dc_device_t *) device); 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 mares_puck_device_set_fingerprint (dc_device_t *abstract, const unsigned char data[], unsigned int size) { diff --git a/src/mares_puck.h b/src/mares_puck.h index 01447d1..421fc28 100644 --- a/src/mares_puck.h +++ b/src/mares_puck.h @@ -23,6 +23,7 @@ #define MARES_PUCK_H #include +#include #include #include @@ -31,7 +32,7 @@ extern "C" { #endif /* __cplusplus */ 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 } diff --git a/src/oceanic_atom2.c b/src/oceanic_atom2.c index 77b946a..f7a9b7a 100644 --- a/src/oceanic_atom2.c +++ b/src/oceanic_atom2.c @@ -26,7 +26,6 @@ #include "oceanic_common.h" #include "context-private.h" #include "device-private.h" -#include "serial.h" #include "array.h" #include "ringbuffer.h" #include "checksum.h" @@ -574,7 +573,7 @@ oceanic_atom2_quit (oceanic_atom2_device_t *device) 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; 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); // Set the default values. - device->iostream = NULL; + device->iostream = iostream; device->delay = 0; device->bigpage = 1; // no big pages device->cached = INVALID; 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. unsigned int baudrate = 38400; 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); if (status != DC_STATUS_SUCCESS) { ERROR (context, "Failed to set the terminal attributes."); - goto error_close; + goto error_free; } // Set the timeout for receiving data (1000 ms). status = dc_iostream_set_timeout (device->iostream, 1000); if (status != DC_STATUS_SUCCESS) { ERROR (context, "Failed to set the timeout."); - goto error_close; + goto error_free; } // 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. status = oceanic_atom2_device_version ((dc_device_t *) device, device->base.version, sizeof (device->base.version)); if (status != DC_STATUS_SUCCESS) { - goto error_close; + goto error_free; } // 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; -error_close: - dc_iostream_close (device->iostream); error_free: dc_device_deallocate ((dc_device_t *) device); return status; @@ -740,12 +730,6 @@ oceanic_atom2_device_close (dc_device_t *abstract) 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; } diff --git a/src/oceanic_atom2.h b/src/oceanic_atom2.h index cee2306..25da953 100644 --- a/src/oceanic_atom2.h +++ b/src/oceanic_atom2.h @@ -23,6 +23,7 @@ #define OCEANIC_ATOM2_H #include +#include #include #include @@ -33,7 +34,7 @@ extern "C" { #endif /* __cplusplus */ 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 oceanic_atom2_parser_create (dc_parser_t **parser, dc_context_t *context, unsigned int model); diff --git a/src/oceanic_veo250.c b/src/oceanic_veo250.c index ffb1c05..42cb676 100644 --- a/src/oceanic_veo250.c +++ b/src/oceanic_veo250.c @@ -26,7 +26,6 @@ #include "oceanic_common.h" #include "context-private.h" #include "device-private.h" -#include "serial.h" #include "ringbuffer.h" #include "checksum.h" @@ -226,7 +225,7 @@ oceanic_veo250_quit (oceanic_veo250_device_t *device) 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; 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; // Set the default values. - device->iostream = NULL; + device->iostream = iostream; 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). status = dc_iostream_configure (device->iostream, 9600, 8, DC_PARITY_NONE, DC_STOPBITS_ONE, DC_FLOWCONTROL_NONE); if (status != DC_STATUS_SUCCESS) { ERROR (context, "Failed to set the terminal attributes."); - goto error_close; + goto error_free; } // Set the timeout for receiving data (3000 ms). status = dc_iostream_set_timeout (device->iostream, 3000); if (status != DC_STATUS_SUCCESS) { ERROR (context, "Failed to set the timeout."); - goto error_close; + goto error_free; } // Set the DTR line. status = dc_iostream_set_dtr (device->iostream, 1); if (status != DC_STATUS_SUCCESS) { ERROR (context, "Failed to set the DTR line."); - goto error_close; + goto error_free; } // Set the RTS line. status = dc_iostream_set_rts (device->iostream, 1); if (status != DC_STATUS_SUCCESS) { 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. @@ -295,7 +287,7 @@ oceanic_veo250_device_open (dc_device_t **out, dc_context_t *context, const char // Initialize the data cable (PPS mode). status = oceanic_veo250_init (device); if (status != DC_STATUS_SUCCESS) { - goto error_close; + goto error_free; } // 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. status = oceanic_veo250_device_version ((dc_device_t *) device, device->base.version, sizeof (device->base.version)); if (status != DC_STATUS_SUCCESS) { - goto error_close; + goto error_free; } // 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; -error_close: - dc_iostream_close (device->iostream); error_free: dc_device_deallocate ((dc_device_t *) device); return status; @@ -342,12 +332,6 @@ oceanic_veo250_device_close (dc_device_t *abstract) 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; } diff --git a/src/oceanic_veo250.h b/src/oceanic_veo250.h index aefd20e..fc79375 100644 --- a/src/oceanic_veo250.h +++ b/src/oceanic_veo250.h @@ -23,6 +23,7 @@ #define OCEANIC_VEO250_H #include +#include #include #include @@ -33,7 +34,7 @@ extern "C" { #endif /* __cplusplus */ 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 oceanic_veo250_parser_create (dc_parser_t **parser, dc_context_t *context, unsigned int model); diff --git a/src/oceanic_vtpro.c b/src/oceanic_vtpro.c index 8635b73..2c9298b 100644 --- a/src/oceanic_vtpro.c +++ b/src/oceanic_vtpro.c @@ -27,7 +27,6 @@ #include "oceanic_common.h" #include "context-private.h" #include "device-private.h" -#include "serial.h" #include "ringbuffer.h" #include "checksum.h" #include "array.h" @@ -389,7 +388,7 @@ oceanic_vtpro_device_logbook (dc_device_t *abstract, dc_event_progress_t *progre } 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; 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; // Set the default values. - device->iostream = NULL; + device->iostream = iostream; device->model = model; if (model == AERIS500AI) { device->protocol = INTR; @@ -419,39 +418,32 @@ oceanic_vtpro_device_open (dc_device_t **out, dc_context_t *context, const char 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). status = dc_iostream_configure (device->iostream, 9600, 8, DC_PARITY_NONE, DC_STOPBITS_ONE, DC_FLOWCONTROL_NONE); if (status != DC_STATUS_SUCCESS) { ERROR (context, "Failed to set the terminal attributes."); - goto error_close; + goto error_free; } // Set the timeout for receiving data (3000 ms). status = dc_iostream_set_timeout (device->iostream, 3000); if (status != DC_STATUS_SUCCESS) { ERROR (context, "Failed to set the timeout."); - goto error_close; + goto error_free; } // Set the DTR line. status = dc_iostream_set_dtr (device->iostream, 1); if (status != DC_STATUS_SUCCESS) { ERROR (context, "Failed to set the DTR line."); - goto error_close; + goto error_free; } // Set the RTS line. status = dc_iostream_set_rts (device->iostream, 1); if (status != DC_STATUS_SUCCESS) { 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. @@ -463,7 +455,7 @@ oceanic_vtpro_device_open (dc_device_t **out, dc_context_t *context, const char // Initialize the data cable (MOD mode). status = oceanic_vtpro_init (device); if (status != DC_STATUS_SUCCESS) { - goto error_close; + goto error_free; } // 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. status = oceanic_vtpro_device_version ((dc_device_t *) device, device->base.version, sizeof (device->base.version)); if (status != DC_STATUS_SUCCESS) { - goto error_close; + goto error_free; } // 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. status = oceanic_vtpro_calibrate (device); if (status != DC_STATUS_SUCCESS) { - goto error_close; + goto error_free; } // 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; -error_close: - dc_iostream_close (device->iostream); error_free: dc_device_deallocate ((dc_device_t *) device); return status; @@ -519,12 +509,6 @@ oceanic_vtpro_device_close (dc_device_t *abstract) 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; } diff --git a/src/oceanic_vtpro.h b/src/oceanic_vtpro.h index 9689818..6a3c2cd 100644 --- a/src/oceanic_vtpro.h +++ b/src/oceanic_vtpro.h @@ -23,6 +23,7 @@ #define OCEANIC_VTPRO_H #include +#include #include #include @@ -33,7 +34,7 @@ extern "C" { #endif /* __cplusplus */ 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 oceanic_vtpro_parser_create (dc_parser_t **parser, dc_context_t *context, unsigned int model); diff --git a/src/reefnet_sensus.c b/src/reefnet_sensus.c index b8d0820..675a4cb 100644 --- a/src/reefnet_sensus.c +++ b/src/reefnet_sensus.c @@ -25,7 +25,6 @@ #include "reefnet_sensus.h" #include "context-private.h" #include "device-private.h" -#include "serial.h" #include "checksum.h" #include "array.h" @@ -86,7 +85,7 @@ reefnet_sensus_cancel (reefnet_sensus_device_t *device) 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; 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. - device->iostream = NULL; + device->iostream = iostream; device->waiting = 0; device->timestamp = 0; device->systime = (dc_ticks_t) -1; device->devtime = 0; 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). status = dc_iostream_configure (device->iostream, 19200, 8, DC_PARITY_NONE, DC_STOPBITS_ONE, DC_FLOWCONTROL_NONE); if (status != DC_STATUS_SUCCESS) { ERROR (context, "Failed to set the terminal attributes."); - goto error_close; + goto error_free; } // Set the timeout for receiving data (3000 ms). status = dc_iostream_set_timeout (device->iostream, 3000); if (status != DC_STATUS_SUCCESS) { ERROR (context, "Failed to set the timeout."); - goto error_close; + goto error_free; } // 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; -error_close: - dc_iostream_close (device->iostream); error_free: dc_device_deallocate ((dc_device_t *) device); 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; } diff --git a/src/reefnet_sensus.h b/src/reefnet_sensus.h index 2ca6d43..a021b86 100644 --- a/src/reefnet_sensus.h +++ b/src/reefnet_sensus.h @@ -23,6 +23,7 @@ #define REEFNET_SENSUS_H #include +#include #include #include #include @@ -32,7 +33,7 @@ extern "C" { #endif /* __cplusplus */ 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 reefnet_sensus_parser_create (dc_parser_t **parser, dc_context_t *context, unsigned int devtime, dc_ticks_t systime); diff --git a/src/reefnet_sensuspro.c b/src/reefnet_sensuspro.c index 0001f1c..b33fe9a 100644 --- a/src/reefnet_sensuspro.c +++ b/src/reefnet_sensuspro.c @@ -25,7 +25,6 @@ #include "reefnet_sensuspro.h" #include "context-private.h" #include "device-private.h" -#include "serial.h" #include "checksum.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_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_close (dc_device_t *abstract); static const dc_device_vtable_t reefnet_sensuspro_device_vtable = { 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_foreach, /* foreach */ NULL, /* timesync */ - reefnet_sensuspro_device_close /* close */ + NULL /* close */ }; 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); 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; 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. - device->iostream = NULL; + device->iostream = iostream; device->timestamp = 0; device->systime = (dc_ticks_t) -1; device->devtime = 0; 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). status = dc_iostream_configure (device->iostream, 19200, 8, DC_PARITY_NONE, DC_STOPBITS_ONE, DC_FLOWCONTROL_NONE); if (status != DC_STATUS_SUCCESS) { ERROR (context, "Failed to set the terminal attributes."); - goto error_close; + goto error_free; } // Set the timeout for receiving data (3000ms). status = dc_iostream_set_timeout (device->iostream, 3000); if (status != DC_STATUS_SUCCESS) { ERROR (context, "Failed to set the timeout."); - goto error_close; + goto error_free; } // 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; -error_close: - dc_iostream_close (device->iostream); error_free: dc_device_deallocate ((dc_device_t *) device); 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 reefnet_sensuspro_device_get_handshake (dc_device_t *abstract, unsigned char data[], unsigned int size) { diff --git a/src/reefnet_sensuspro.h b/src/reefnet_sensuspro.h index 000959a..9932515 100644 --- a/src/reefnet_sensuspro.h +++ b/src/reefnet_sensuspro.h @@ -23,6 +23,7 @@ #define REEFNET_SENSUSPRO_H #include +#include #include #include #include @@ -32,7 +33,7 @@ extern "C" { #endif /* __cplusplus */ 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 reefnet_sensuspro_parser_create (dc_parser_t **parser, dc_context_t *context, unsigned int devtime, dc_ticks_t systime); diff --git a/src/reefnet_sensusultra.c b/src/reefnet_sensusultra.c index 9ac95a2..22ffe81 100644 --- a/src/reefnet_sensusultra.c +++ b/src/reefnet_sensusultra.c @@ -26,7 +26,6 @@ #include "reefnet_sensusultra.h" #include "context-private.h" #include "device-private.h" -#include "serial.h" #include "checksum.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_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_close (dc_device_t *abstract); static const dc_device_vtable_t reefnet_sensusultra_device_vtable = { 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_foreach, /* foreach */ NULL, /* timesync */ - reefnet_sensusultra_device_close /* close */ + NULL /* close */ }; 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; 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. - device->iostream = NULL; + device->iostream = iostream; device->timestamp = 0; device->systime = (dc_ticks_t) -1; device->devtime = 0; 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). status = dc_iostream_configure (device->iostream, 115200, 8, DC_PARITY_NONE, DC_STOPBITS_ONE, DC_FLOWCONTROL_NONE); if (status != DC_STATUS_SUCCESS) { ERROR (context, "Failed to set the terminal attributes."); - goto error_close; + goto error_free; } // Set the timeout for receiving data (3000ms). status = dc_iostream_set_timeout (device->iostream, 3000); if (status != DC_STATUS_SUCCESS) { ERROR (context, "Failed to set the timeout."); - goto error_close; + goto error_free; } // 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; -error_close: - dc_iostream_close (device->iostream); error_free: dc_device_deallocate ((dc_device_t *) device); 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 reefnet_sensusultra_device_get_handshake (dc_device_t *abstract, unsigned char data[], unsigned int size) { diff --git a/src/reefnet_sensusultra.h b/src/reefnet_sensusultra.h index 84fcaea..af73c8a 100644 --- a/src/reefnet_sensusultra.h +++ b/src/reefnet_sensusultra.h @@ -23,6 +23,7 @@ #define REEFNET_SENSUSULTRA_H #include +#include #include #include #include @@ -32,7 +33,7 @@ extern "C" { #endif /* __cplusplus */ 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 reefnet_sensusultra_parser_create (dc_parser_t **parser, dc_context_t *context, unsigned int devtime, dc_ticks_t systime); diff --git a/src/serial_posix.c b/src/serial_posix.c index 6f2ae71..ff954ef 100644 --- a/src/serial_posix.c +++ b/src/serial_posix.c @@ -52,7 +52,7 @@ #define NOPTY 1 #endif -#include "serial.h" +#include #include "common-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); // 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) { SYSERROR (context, ENOMEM); return DC_STATUS_NOMEMORY; diff --git a/src/serial_win32.c b/src/serial_win32.c index b0c6050..ff52b41 100644 --- a/src/serial_win32.c +++ b/src/serial_win32.c @@ -24,7 +24,7 @@ #define NOGDI #include -#include "serial.h" +#include #include "common-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. - 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) { SYSERROR (context, ERROR_OUTOFMEMORY); return DC_STATUS_NOMEMORY; diff --git a/src/shearwater_common.c b/src/shearwater_common.c index a6b454d..130ff62 100644 --- a/src/shearwater_common.c +++ b/src/shearwater_common.c @@ -36,29 +36,24 @@ #define ESC_ESC 0xDD 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; - // Open the device. - status = dc_serial_open (&device->iostream, context, name); - if (status != DC_STATUS_SUCCESS) { - ERROR (context, "Failed to open the serial port."); - return status; - } + device->iostream = iostream; // Set the serial communication protocol (115200 8N1). status = dc_iostream_configure (device->iostream, 115200, 8, DC_PARITY_NONE, DC_STOPBITS_ONE, DC_FLOWCONTROL_NONE); if (status != DC_STATUS_SUCCESS) { ERROR (context, "Failed to set the terminal attributes."); - goto error_close; + return status; } // Set the timeout for receiving data (3000ms). status = dc_iostream_set_timeout (device->iostream, 3000); if (status != DC_STATUS_SUCCESS) { ERROR (context, "Failed to set the timeout."); - goto error_close; + return status; } // 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); 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); } diff --git a/src/shearwater_common.h b/src/shearwater_common.h index 3075f99..767372f 100644 --- a/src/shearwater_common.h +++ b/src/shearwater_common.h @@ -22,8 +22,9 @@ #ifndef SHEARWATER_COMMON_H #define SHEARWATER_COMMON_H +#include + #include "device-private.h" -#include "serial.h" #ifdef __cplusplus extern "C" { @@ -49,10 +50,7 @@ typedef struct shearwater_common_device_t { } shearwater_common_device_t; dc_status_t -shearwater_common_open (shearwater_common_device_t *device, dc_context_t *context, const char *name); - -dc_status_t -shearwater_common_close (shearwater_common_device_t *device); +shearwater_common_setup (shearwater_common_device_t *device, dc_context_t *context, dc_iostream_t *iostream); 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); diff --git a/src/shearwater_petrel.c b/src/shearwater_petrel.c index 2f040dc..2e87a3f 100644 --- a/src/shearwater_petrel.c +++ b/src/shearwater_petrel.c @@ -77,7 +77,7 @@ str2num (unsigned char data[], unsigned int size, unsigned int offset) 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; 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. memset (device->fingerprint, 0, sizeof (device->fingerprint)); - // Open the device. - status = shearwater_common_open (&device->base, context, name); + // Setup the device. + status = shearwater_common_setup (&device->base, context, iostream); if (status != DC_STATUS_SUCCESS) { goto error_free; } @@ -125,12 +125,6 @@ shearwater_petrel_device_close (dc_device_t *abstract) 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; } diff --git a/src/shearwater_petrel.h b/src/shearwater_petrel.h index c23bb74..0a4e756 100644 --- a/src/shearwater_petrel.h +++ b/src/shearwater_petrel.h @@ -23,6 +23,7 @@ #define SHEARWATER_PETREL_H #include +#include #include #include @@ -31,7 +32,7 @@ extern "C" { #endif /* __cplusplus */ 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 shearwater_petrel_parser_create (dc_parser_t **parser, dc_context_t *context, unsigned int model); diff --git a/src/shearwater_predator.c b/src/shearwater_predator.c index 6326785..e861c37 100644 --- a/src/shearwater_predator.c +++ b/src/shearwater_predator.c @@ -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_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_close (dc_device_t *abstract); static const dc_device_vtable_t shearwater_predator_device_vtable = { 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_foreach, /* foreach */ NULL, /* timesync */ - shearwater_predator_device_close /* close */ + NULL /* close */ }; 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); 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; 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. memset (device->fingerprint, 0, sizeof (device->fingerprint)); - // Open the device. - status = shearwater_common_open (&device->base, context, name); + // Setup the device. + status = shearwater_common_setup (&device->base, context, iostream); if (status != DC_STATUS_SUCCESS) { 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 shearwater_predator_device_set_fingerprint (dc_device_t *abstract, const unsigned char data[], unsigned int size) { diff --git a/src/shearwater_predator.h b/src/shearwater_predator.h index 4665f80..5d1fccb 100644 --- a/src/shearwater_predator.h +++ b/src/shearwater_predator.h @@ -23,6 +23,7 @@ #define SHEARWATER_PREDATOR_H #include +#include #include #include @@ -31,7 +32,7 @@ extern "C" { #endif /* __cplusplus */ 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 shearwater_predator_parser_create (dc_parser_t **parser, dc_context_t *context, unsigned int model); diff --git a/src/suunto_d9.c b/src/suunto_d9.c index 8c2834c..ab6eee1 100644 --- a/src/suunto_d9.c +++ b/src/suunto_d9.c @@ -26,7 +26,6 @@ #include "suunto_d9.h" #include "suunto_common2.h" #include "context-private.h" -#include "serial.h" #include "checksum.h" #include "array.h" @@ -48,7 +47,6 @@ typedef struct 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_close (dc_device_t *abstract); 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_foreach, /* foreach */ NULL, /* timesync */ - suunto_d9_device_close /* close */ + NULL /* close */ }, suunto_d9_device_packet }; @@ -128,7 +126,7 @@ suunto_d9_device_autodetect (suunto_d9_device_t *device, unsigned int model) 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; 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); // Set the default values. - device->iostream = NULL; - - // 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; - } + device->iostream = iostream; // Set the serial communication protocol (9600 8N1). status = dc_iostream_configure (device->iostream, 9600, 8, DC_PARITY_NONE, DC_STOPBITS_ONE, DC_FLOWCONTROL_NONE); if (status != DC_STATUS_SUCCESS) { ERROR (context, "Failed to set the terminal attributes."); - goto error_close; + goto error_free; } // Set the timeout for receiving data (3000 ms). status = dc_iostream_set_timeout (device->iostream, 3000); if (status != DC_STATUS_SUCCESS) { ERROR (context, "Failed to set the timeout."); - goto error_close; + goto error_free; } // Set the DTR line (power supply for the interface). status = dc_iostream_set_dtr (device->iostream, 1); if (status != DC_STATUS_SUCCESS) { 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. @@ -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); if (status != DC_STATUS_SUCCESS) { ERROR (context, "Failed to identify the protocol variant."); - goto error_close; + goto error_free; } // 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; -error_close: - dc_iostream_close (device->iostream); error_free: dc_device_deallocate ((dc_device_t *) device); 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 suunto_d9_device_packet (dc_device_t *abstract, const unsigned char command[], unsigned int csize, unsigned char answer[], unsigned int asize, unsigned int size) { diff --git a/src/suunto_d9.h b/src/suunto_d9.h index 91fe8b2..94a782f 100644 --- a/src/suunto_d9.h +++ b/src/suunto_d9.h @@ -23,6 +23,7 @@ #define SUUNTO_D9_H #include +#include #include #include #include @@ -32,7 +33,7 @@ extern "C" { #endif /* __cplusplus */ 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 suunto_d9_parser_create (dc_parser_t **parser, dc_context_t *context, unsigned int model); diff --git a/src/suunto_eon.c b/src/suunto_eon.c index 8b9138c..84fc367 100644 --- a/src/suunto_eon.c +++ b/src/suunto_eon.c @@ -26,7 +26,6 @@ #include "suunto_common.h" #include "context-private.h" #include "device-private.h" -#include "serial.h" #include "checksum.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_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 = { 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_foreach, /* foreach */ NULL, /* timesync */ - suunto_eon_device_close /* close */ + NULL /* close */ }; 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 -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; 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); // Set the default values. - device->iostream = NULL; - - // 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; - } + device->iostream = iostream; // Set the serial communication protocol (1200 8N2). status = dc_iostream_configure (device->iostream, 1200, 8, DC_PARITY_NONE, DC_STOPBITS_TWO, DC_FLOWCONTROL_NONE); if (status != DC_STATUS_SUCCESS) { ERROR (context, "Failed to set the terminal attributes."); - goto error_close; + goto error_free; } // Set the timeout for receiving data (1000ms). status = dc_iostream_set_timeout (device->iostream, 1000); if (status != DC_STATUS_SUCCESS) { ERROR (context, "Failed to set the timeout."); - goto error_close; + goto error_free; } // Clear the RTS line. status = dc_iostream_set_rts (device->iostream, 0); if (status != DC_STATUS_SUCCESS) { ERROR (context, "Failed to set the DTR/RTS line."); - goto error_close; + goto error_free; } *out = (dc_device_t*) device; return DC_STATUS_SUCCESS; -error_close: - dc_iostream_close (device->iostream); error_free: dc_device_deallocate ((dc_device_t *) device); 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 suunto_eon_device_dump (dc_device_t *abstract, dc_buffer_t *buffer) { diff --git a/src/suunto_eon.h b/src/suunto_eon.h index 2adce91..5e99a69 100644 --- a/src/suunto_eon.h +++ b/src/suunto_eon.h @@ -23,6 +23,7 @@ #define SUUNTO_EON_H #include +#include #include #include #include @@ -32,7 +33,7 @@ extern "C" { #endif /* __cplusplus */ 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 suunto_eon_parser_create (dc_parser_t **parser, dc_context_t *context, int spyder); diff --git a/src/suunto_eonsteel.c b/src/suunto_eonsteel.c index 5f4ad02..6c430b4 100644 --- a/src/suunto_eonsteel.c +++ b/src/suunto_eonsteel.c @@ -27,7 +27,6 @@ #include "context-private.h" #include "device-private.h" #include "array.h" -#include "usbhid.h" #include "platform.h" #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_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_close(dc_device_t *abstract); static const dc_device_vtable_t suunto_eonsteel_device_vtable = { sizeof(suunto_eonsteel_device_t), @@ -92,7 +90,7 @@ static const dc_device_vtable_t suunto_eonsteel_device_vtable = { NULL, /* dump */ suunto_eonsteel_device_foreach, /* foreach */ suunto_eonsteel_device_timesync, /* timesync */ - suunto_eonsteel_device_close /* close */ + NULL /* close */ }; 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 -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; 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; // Set up the magic handshake fields + eon->iostream = iostream; eon->model = model; eon->magic = INIT_MAGIC; eon->seq = INIT_SEQ; memset (eon->version, 0, sizeof (eon->version)); 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); if (status != DC_STATUS_SUCCESS) { ERROR (context, "Failed to set the timeout."); - goto error_close; + goto error_free; } 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); if (status != DC_STATUS_SUCCESS) { ERROR(context, "unable to initialize device"); - goto error_close; + goto error_free; } *out = (dc_device_t *) eon; return DC_STATUS_SUCCESS; -error_close: - dc_iostream_close(eon->iostream); error_free: free(eon); return status; @@ -777,13 +762,3 @@ static dc_status_t suunto_eonsteel_device_timesync(dc_device_t *abstract, const 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; -} diff --git a/src/suunto_eonsteel.h b/src/suunto_eonsteel.h index 2927dce..2800107 100644 --- a/src/suunto_eonsteel.h +++ b/src/suunto_eonsteel.h @@ -23,6 +23,7 @@ #define SUUNTO_EONSTEEL_H #include +#include #include #include @@ -31,7 +32,7 @@ extern "C" { #endif /* __cplusplus */ 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 suunto_eonsteel_parser_create(dc_parser_t **parser, dc_context_t *context, unsigned int model); diff --git a/src/suunto_solution.c b/src/suunto_solution.c index 9480252..a09c6d5 100644 --- a/src/suunto_solution.c +++ b/src/suunto_solution.c @@ -27,7 +27,6 @@ #include "context-private.h" #include "device-private.h" #include "ringbuffer.h" -#include "serial.h" #include "array.h" #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_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 = { 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_foreach, /* foreach */ NULL, /* timesync */ - suunto_solution_device_close /* close */ + NULL /* close */ }; 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); 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; 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. - device->iostream = NULL; - - // 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; - } + device->iostream = iostream; // Set the serial communication protocol (1200 8N2). status = dc_iostream_configure (device->iostream, 1200, 8, DC_PARITY_NONE, DC_STOPBITS_TWO, DC_FLOWCONTROL_NONE); if (status != DC_STATUS_SUCCESS) { ERROR (context, "Failed to set the terminal attributes."); - goto error_close; + goto error_free; } // Set the timeout for receiving data (1000ms). status = dc_iostream_set_timeout (device->iostream, 1000); if (status != DC_STATUS_SUCCESS) { ERROR (context, "Failed to set the timeout."); - goto error_close; + goto error_free; } // Clear the RTS line. status = dc_iostream_set_rts (device->iostream, 0); if (status != DC_STATUS_SUCCESS) { ERROR (context, "Failed to set the DTR/RTS line."); - goto error_close; + goto error_free; } *out = (dc_device_t*) device; return DC_STATUS_SUCCESS; -error_close: - dc_iostream_close (device->iostream); error_free: dc_device_deallocate ((dc_device_t *) device); 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 suunto_solution_device_dump (dc_device_t *abstract, dc_buffer_t *buffer) { diff --git a/src/suunto_solution.h b/src/suunto_solution.h index e322583..9d9e632 100644 --- a/src/suunto_solution.h +++ b/src/suunto_solution.h @@ -23,6 +23,7 @@ #define SUUNTO_SOLUTION_H #include +#include #include #include @@ -31,7 +32,7 @@ extern "C" { #endif /* __cplusplus */ 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 suunto_solution_parser_create (dc_parser_t **parser, dc_context_t *context); diff --git a/src/suunto_vyper.c b/src/suunto_vyper.c index 276e633..fe3b405 100644 --- a/src/suunto_vyper.c +++ b/src/suunto_vyper.c @@ -27,7 +27,6 @@ #include "suunto_common.h" #include "context-private.h" #include "device-private.h" -#include "serial.h" #include "checksum.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_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_close (dc_device_t *abstract); static const dc_device_vtable_t suunto_vyper_device_vtable = { 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_foreach, /* foreach */ NULL, /* timesync */ - suunto_vyper_device_close /* close */ + NULL /* close */ }; 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 -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; 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); // Set the default values. - device->iostream = NULL; - - // 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; - } + device->iostream = iostream; // Set the serial communication protocol (2400 8O1). status = dc_iostream_configure (device->iostream, 2400, 8, DC_PARITY_ODD, DC_STOPBITS_ONE, DC_FLOWCONTROL_NONE); if (status != DC_STATUS_SUCCESS) { ERROR (context, "Failed to set the terminal attributes."); - goto error_close; + goto error_free; } // Set the timeout for receiving data (1000 ms). status = dc_iostream_set_timeout (device->iostream, 1000); if (status != DC_STATUS_SUCCESS) { ERROR (context, "Failed to set the timeout."); - goto error_close; + goto error_free; } // Set the DTR line (power supply for the interface). status = dc_iostream_set_dtr (device->iostream, 1); if (status != DC_STATUS_SUCCESS) { 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. @@ -144,31 +135,12 @@ suunto_vyper_device_open (dc_device_t **out, dc_context_t *context, const char * return DC_STATUS_SUCCESS; -error_close: - dc_iostream_close (device->iostream); error_free: dc_device_deallocate ((dc_device_t *) device); 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 suunto_vyper_send (suunto_vyper_device_t *device, const unsigned char command[], unsigned int csize) { diff --git a/src/suunto_vyper.h b/src/suunto_vyper.h index 95f1a4a..858520f 100644 --- a/src/suunto_vyper.h +++ b/src/suunto_vyper.h @@ -23,6 +23,7 @@ #define SUUNTO_VYPER_H #include +#include #include #include @@ -31,7 +32,7 @@ extern "C" { #endif /* __cplusplus */ 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 suunto_vyper_parser_create (dc_parser_t **parser, dc_context_t *context); diff --git a/src/suunto_vyper2.c b/src/suunto_vyper2.c index 596b06e..02f38ed 100644 --- a/src/suunto_vyper2.c +++ b/src/suunto_vyper2.c @@ -25,7 +25,6 @@ #include "suunto_vyper2.h" #include "suunto_common2.h" #include "context-private.h" -#include "serial.h" #include "checksum.h" #include "array.h" #include "timer.h" @@ -76,7 +75,7 @@ static const suunto_common2_layout_t suunto_helo2_layout = { 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; 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); // Set the default values. - device->iostream = NULL; + device->iostream = iostream; // Create a high resolution 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; } - // 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). status = dc_iostream_configure (device->iostream, 9600, 8, DC_PARITY_NONE, DC_STOPBITS_ONE, DC_FLOWCONTROL_NONE); if (status != DC_STATUS_SUCCESS) { ERROR (context, "Failed to set the terminal attributes."); - goto error_close; + goto error_timer_free; } // Set the timeout for receiving data (3000 ms). status = dc_iostream_set_timeout (device->iostream, 3000); if (status != DC_STATUS_SUCCESS) { ERROR (context, "Failed to set the timeout."); - goto error_close; + goto error_timer_free; } // Set the DTR line (power supply for the interface). status = dc_iostream_set_dtr (device->iostream, 1); if (status != DC_STATUS_SUCCESS) { 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. @@ -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); if (status != DC_STATUS_SUCCESS) { ERROR (context, "Failed to reset IO state."); - goto error_close; + goto error_timer_free; } // Read the version info. status = suunto_common2_device_version ((dc_device_t *) device, device->base.version, sizeof (device->base.version)); if (status != DC_STATUS_SUCCESS) { ERROR (context, "Failed to read the version info."); - goto error_close; + goto error_timer_free; } // 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; -error_close: - dc_iostream_close (device->iostream); error_timer_free: dc_timer_free (device->timer); error_free: @@ -173,19 +163,11 @@ error_free: static dc_status_t 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; - dc_status_t rc = DC_STATUS_SUCCESS; dc_timer_free (device->timer); - // Close the device. - rc = dc_iostream_close (device->iostream); - if (rc != DC_STATUS_SUCCESS) { - dc_status_set_error(&status, rc); - } - - return status; + return DC_STATUS_SUCCESS; } diff --git a/src/suunto_vyper2.h b/src/suunto_vyper2.h index b6486d9..0fc7fc8 100644 --- a/src/suunto_vyper2.h +++ b/src/suunto_vyper2.h @@ -27,11 +27,12 @@ extern "C" { #endif /* __cplusplus */ #include +#include #include #include 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 } diff --git a/src/usbhid.c b/src/usbhid.c index 244e175..0d3bb8a 100644 --- a/src/usbhid.c +++ b/src/usbhid.c @@ -49,7 +49,7 @@ #include #endif -#include "usbhid.h" +#include #include "common-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); // 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) { ERROR (context, "Out of memory."); return DC_STATUS_NOMEMORY; diff --git a/src/uwatec_aladin.c b/src/uwatec_aladin.c index 0f1a49a..3ebd094 100644 --- a/src/uwatec_aladin.c +++ b/src/uwatec_aladin.c @@ -25,7 +25,6 @@ #include "uwatec_aladin.h" #include "context-private.h" #include "device-private.h" -#include "serial.h" #include "ringbuffer.h" #include "checksum.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_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_close (dc_device_t *abstract); static const dc_device_vtable_t uwatec_aladin_device_vtable = { 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_foreach, /* foreach */ NULL, /* timesync */ - uwatec_aladin_device_close /* close */ + NULL /* close */ }; 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); 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; 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. - device->iostream = NULL; + device->iostream = iostream; device->timestamp = 0; device->systime = (dc_ticks_t) -1; 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). status = dc_iostream_configure (device->iostream, 19200, 8, DC_PARITY_NONE, DC_STOPBITS_ONE, DC_FLOWCONTROL_NONE); if (status != DC_STATUS_SUCCESS) { ERROR (context, "Failed to set the terminal attributes."); - goto error_close; + goto error_free; } // Set the timeout for receiving data (INFINITE). status = dc_iostream_set_timeout (device->iostream, -1); if (status != DC_STATUS_SUCCESS) { ERROR (context, "Failed to set the timeout."); - goto error_close; + goto error_free; } // Set the DTR line. status = dc_iostream_set_dtr (device->iostream, 1); if (status != DC_STATUS_SUCCESS) { ERROR (context, "Failed to set the DTR line."); - goto error_close; + goto error_free; } // Clear the RTS line. status = dc_iostream_set_rts (device->iostream, 0); if (status != DC_STATUS_SUCCESS) { ERROR (context, "Failed to clear the RTS line."); - goto error_close; + goto error_free; } *out = (dc_device_t*) device; return DC_STATUS_SUCCESS; -error_close: - dc_iostream_close (device->iostream); error_free: dc_device_deallocate ((dc_device_t *) device); 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 uwatec_aladin_device_set_fingerprint (dc_device_t *abstract, const unsigned char data[], unsigned int size) { diff --git a/src/uwatec_aladin.h b/src/uwatec_aladin.h index 41484f6..7579871 100644 --- a/src/uwatec_aladin.h +++ b/src/uwatec_aladin.h @@ -27,10 +27,11 @@ extern "C" { #endif /* __cplusplus */ #include +#include #include 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 } diff --git a/src/uwatec_g2.c b/src/uwatec_g2.c index fc24b71..ea2d324 100644 --- a/src/uwatec_g2.c +++ b/src/uwatec_g2.c @@ -26,7 +26,6 @@ #include "uwatec_g2.h" #include "context-private.h" #include "device-private.h" -#include "usbhid.h" #include "array.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_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_close (dc_device_t *abstract); static const dc_device_vtable_t uwatec_g2_device_vtable = { 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_foreach, /* foreach */ NULL, /* timesync */ - uwatec_g2_device_close /* close */ + NULL /* close */ }; static dc_status_t @@ -180,7 +178,7 @@ uwatec_g2_handshake (uwatec_g2_device_t *device) 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; 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. - device->iostream = NULL; + device->iostream = iostream; device->timestamp = 0; device->systime = (dc_ticks_t) -1; 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. status = uwatec_g2_handshake (device); if (status != DC_STATUS_SUCCESS) { ERROR (context, "Failed to handshake with the device."); - goto error_close; + goto error_free; } *out = (dc_device_t*) device; return DC_STATUS_SUCCESS; -error_close: - dc_iostream_close (device->iostream); error_free: dc_device_deallocate ((dc_device_t *) device); 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 uwatec_g2_device_set_fingerprint (dc_device_t *abstract, const unsigned char data[], unsigned int size) { diff --git a/src/uwatec_g2.h b/src/uwatec_g2.h index 801e15d..72a4390 100644 --- a/src/uwatec_g2.h +++ b/src/uwatec_g2.h @@ -23,6 +23,7 @@ #define UWATEC_G2_H #include +#include #include #include @@ -31,7 +32,7 @@ extern "C" { #endif /* __cplusplus */ 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 } diff --git a/src/uwatec_memomouse.c b/src/uwatec_memomouse.c index ca3a747..c77b598 100644 --- a/src/uwatec_memomouse.c +++ b/src/uwatec_memomouse.c @@ -26,7 +26,6 @@ #include "uwatec_memomouse.h" #include "context-private.h" #include "device-private.h" -#include "serial.h" #include "checksum.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_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_close (dc_device_t *abstract); static const dc_device_vtable_t uwatec_memomouse_device_vtable = { 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_foreach, /* foreach */ NULL, /* timesync */ - uwatec_memomouse_device_close /* close */ + NULL /* close */ }; 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); 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; 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. - device->iostream = NULL; + device->iostream = iostream; device->timestamp = 0; device->systime = (dc_ticks_t) -1; 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). status = dc_iostream_configure (device->iostream, 9600, 8, DC_PARITY_NONE, DC_STOPBITS_ONE, DC_FLOWCONTROL_NONE); if (status != DC_STATUS_SUCCESS) { ERROR (context, "Failed to set the terminal attributes."); - goto error_close; + goto error_free; } // Set the timeout for receiving data (1000 ms). status = dc_iostream_set_timeout (device->iostream, 1000); if (status != DC_STATUS_SUCCESS) { ERROR (context, "Failed to set the timeout."); - goto error_close; + goto error_free; } // Clear the DTR line. status = dc_iostream_set_dtr (device->iostream, 0); if (status != DC_STATUS_SUCCESS) { ERROR (context, "Failed to clear the DTR line."); - goto error_close; + goto error_free; } // Clear the RTS line. status = dc_iostream_set_rts (device->iostream, 0); if (status != DC_STATUS_SUCCESS) { ERROR (context, "Failed to clear the RTS line."); - goto error_close; + goto error_free; } // 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; -error_close: - dc_iostream_close (device->iostream); error_free: dc_device_deallocate ((dc_device_t *) device); 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 uwatec_memomouse_device_set_fingerprint (dc_device_t *abstract, const unsigned char data[], unsigned int size) { diff --git a/src/uwatec_memomouse.h b/src/uwatec_memomouse.h index 8d37dc6..49ecf9e 100644 --- a/src/uwatec_memomouse.h +++ b/src/uwatec_memomouse.h @@ -23,6 +23,7 @@ #define UWATEC_MEMOMOUSE_H #include +#include #include #include @@ -31,7 +32,7 @@ extern "C" { #endif /* __cplusplus */ dc_status_t -uwatec_memomouse_device_open (dc_device_t **device, dc_context_t *context, const char *name); +uwatec_memomouse_device_open (dc_device_t **device, dc_context_t *context, dc_iostream_t *iostream); dc_status_t uwatec_memomouse_parser_create (dc_parser_t **parser, dc_context_t *context, unsigned int devtime, dc_ticks_t systime); diff --git a/src/uwatec_meridian.c b/src/uwatec_meridian.c index 17f1b62..378facb 100644 --- a/src/uwatec_meridian.c +++ b/src/uwatec_meridian.c @@ -27,7 +27,6 @@ #include "context-private.h" #include "device-private.h" #include "checksum.h" -#include "serial.h" #include "array.h" #define ISINSTANCE(device) dc_device_isinstance((device), &uwatec_meridian_device_vtable) @@ -46,7 +45,6 @@ typedef struct uwatec_meridian_device_t { static dc_status_t uwatec_meridian_device_set_fingerprint (dc_device_t *device, const unsigned char data[], unsigned int size); static dc_status_t uwatec_meridian_device_dump (dc_device_t *abstract, dc_buffer_t *buffer); static dc_status_t uwatec_meridian_device_foreach (dc_device_t *abstract, dc_dive_callback_t callback, void *userdata); -static dc_status_t uwatec_meridian_device_close (dc_device_t *abstract); static const dc_device_vtable_t uwatec_meridian_device_vtable = { sizeof(uwatec_meridian_device_t), @@ -57,7 +55,7 @@ static const dc_device_vtable_t uwatec_meridian_device_vtable = { uwatec_meridian_device_dump, /* dump */ uwatec_meridian_device_foreach, /* foreach */ NULL, /* timesync */ - uwatec_meridian_device_close /* close */ + NULL /* close */ }; static dc_status_t @@ -183,7 +181,7 @@ uwatec_meridian_handshake (uwatec_meridian_device_t *device) dc_status_t -uwatec_meridian_device_open (dc_device_t **out, dc_context_t *context, const char *name) +uwatec_meridian_device_open (dc_device_t **out, dc_context_t *context, dc_iostream_t *iostream) { dc_status_t status = DC_STATUS_SUCCESS; uwatec_meridian_device_t *device = NULL; @@ -199,30 +197,23 @@ uwatec_meridian_device_open (dc_device_t **out, dc_context_t *context, const cha } // Set the default values. - device->iostream = NULL; + device->iostream = iostream; device->timestamp = 0; device->systime = (dc_ticks_t) -1; 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 (57600 8N1). status = dc_iostream_configure (device->iostream, 57600, 8, DC_PARITY_NONE, DC_STOPBITS_ONE, DC_FLOWCONTROL_NONE); if (status != DC_STATUS_SUCCESS) { ERROR (context, "Failed to set the terminal attributes."); - goto error_close; + goto error_free; } // Set the timeout for receiving data (3000ms). status = dc_iostream_set_timeout (device->iostream, 3000); if (status != DC_STATUS_SUCCESS) { ERROR (context, "Failed to set the timeout."); - goto error_close; + goto error_free; } // Make sure everything is in a sane state. @@ -232,38 +223,19 @@ uwatec_meridian_device_open (dc_device_t **out, dc_context_t *context, const cha status = uwatec_meridian_handshake (device); if (status != DC_STATUS_SUCCESS) { ERROR (context, "Failed to handshake with the device."); - goto error_close; + goto error_free; } *out = (dc_device_t*) device; return DC_STATUS_SUCCESS; -error_close: - dc_iostream_close (device->iostream); error_free: dc_device_deallocate ((dc_device_t *) device); return status; } -static dc_status_t -uwatec_meridian_device_close (dc_device_t *abstract) -{ - dc_status_t status = DC_STATUS_SUCCESS; - uwatec_meridian_device_t *device = (uwatec_meridian_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 uwatec_meridian_device_set_fingerprint (dc_device_t *abstract, const unsigned char data[], unsigned int size) { diff --git a/src/uwatec_meridian.h b/src/uwatec_meridian.h index 9c6918c..4ac80d3 100644 --- a/src/uwatec_meridian.h +++ b/src/uwatec_meridian.h @@ -23,6 +23,7 @@ #define UWATEC_MERIDIAN_H #include +#include #include #include @@ -31,7 +32,7 @@ extern "C" { #endif /* __cplusplus */ dc_status_t -uwatec_meridian_device_open (dc_device_t **device, dc_context_t *context, const char *name); +uwatec_meridian_device_open (dc_device_t **device, dc_context_t *context, dc_iostream_t *iostream); #ifdef __cplusplus } diff --git a/src/uwatec_smart.c b/src/uwatec_smart.c index a3be17d..9bf0f99 100644 --- a/src/uwatec_smart.c +++ b/src/uwatec_smart.c @@ -25,9 +25,7 @@ #include "uwatec_smart.h" #include "context-private.h" #include "device-private.h" -#include "irda.h" #include "array.h" -#include "platform.h" #define ISINSTANCE(device) dc_device_isinstance((device), &uwatec_smart_device_vtable) @@ -44,7 +42,6 @@ typedef struct uwatec_smart_device_t { static dc_status_t uwatec_smart_device_set_fingerprint (dc_device_t *device, const unsigned char data[], unsigned int size); static dc_status_t uwatec_smart_device_dump (dc_device_t *abstract, dc_buffer_t *buffer); static dc_status_t uwatec_smart_device_foreach (dc_device_t *abstract, dc_dive_callback_t callback, void *userdata); -static dc_status_t uwatec_smart_device_close (dc_device_t *abstract); static const dc_device_vtable_t uwatec_smart_device_vtable = { sizeof(uwatec_smart_device_t), @@ -55,38 +52,12 @@ static const dc_device_vtable_t uwatec_smart_device_vtable = { uwatec_smart_device_dump, /* dump */ uwatec_smart_device_foreach, /* foreach */ NULL, /* timesync */ - uwatec_smart_device_close /* close */ + NULL /* close */ }; static dc_status_t uwatec_smart_extract_dives (dc_device_t *device, const unsigned char data[], unsigned int size, dc_dive_callback_t callback, void *userdata); -static int -uwatec_smart_filter (const char *name) -{ - static const char *names[] = { - "Aladin Smart Com", - "Aladin Smart Pro", - "Aladin Smart Tec", - "Aladin Smart Z", - "Uwatec Aladin", - "UWATEC Galileo", - "UWATEC Galileo Sol", - }; - - if (name == NULL) - return 0; - - for (size_t i = 0; i < C_ARRAY_SIZE(names); ++i) { - if (strcasecmp(name, names[i]) == 0) { - return 1; - } - } - - return 0; -} - - static dc_status_t uwatec_smart_transfer (uwatec_smart_device_t *device, const unsigned char command[], unsigned int csize, unsigned char answer[], unsigned int asize) { @@ -147,12 +118,10 @@ uwatec_smart_handshake (uwatec_smart_device_t *device) dc_status_t -uwatec_smart_device_open (dc_device_t **out, dc_context_t *context) +uwatec_smart_device_open (dc_device_t **out, dc_context_t *context, dc_iostream_t *iostream) { dc_status_t status = DC_STATUS_SUCCESS; uwatec_smart_device_t *device = NULL; - dc_iterator_t *iterator = NULL; - dc_irda_device_t *dev = NULL; if (out == NULL) return DC_STATUS_INVALIDARGS; @@ -165,80 +134,28 @@ uwatec_smart_device_open (dc_device_t **out, dc_context_t *context) } // Set the default values. - device->iostream = NULL; + device->iostream = iostream; device->timestamp = 0; device->systime = (dc_ticks_t) -1; device->devtime = 0; - // Create the irda device iterator. - status = dc_irda_iterator_new (&iterator, context, NULL); - if (status != DC_STATUS_SUCCESS) { - ERROR (context, "Failed to create the irda iterator."); - goto error_free; - } - - // Enumerate the irda devices. - while (1) { - dc_irda_device_t *current = NULL; - status = dc_iterator_next (iterator, ¤t); - if (status != DC_STATUS_SUCCESS) { - if (status == DC_STATUS_DONE) { - ERROR (context, "No dive computer found."); - status = DC_STATUS_NODEVICE; - } else { - ERROR (context, "Failed to enumerate the irda devices."); - } - goto error_iterator_free; - } - - if (uwatec_smart_filter (dc_irda_device_get_name (current))) { - dev = current; - break; - } - - dc_irda_device_free (current); - } - - // Open the irda socket. - status = dc_irda_open (&device->iostream, context, dc_irda_device_get_address (dev), 1); - if (status != DC_STATUS_SUCCESS) { - ERROR (context, "Failed to open the irda socket."); - goto error_device_free; - } - // Perform the handshaking. status = uwatec_smart_handshake (device); if (status != DC_STATUS_SUCCESS) { ERROR (context, "Failed to handshake with the device."); - goto error_close; + goto error_free; } *out = (dc_device_t*) device; return DC_STATUS_SUCCESS; -error_close: - dc_iostream_close (device->iostream); -error_device_free: - dc_irda_device_free (dev); -error_iterator_free: - dc_iterator_free (iterator); error_free: dc_device_deallocate ((dc_device_t *) device); return status; } -static dc_status_t -uwatec_smart_device_close (dc_device_t *abstract) -{ - uwatec_smart_device_t *device = (uwatec_smart_device_t*) abstract; - - // Close the device and pass up the return code. - return dc_iostream_close (device->iostream); -} - - static dc_status_t uwatec_smart_device_set_fingerprint (dc_device_t *abstract, const unsigned char data[], unsigned int size) { diff --git a/src/uwatec_smart.h b/src/uwatec_smart.h index 5304c73..2f7f2b9 100644 --- a/src/uwatec_smart.h +++ b/src/uwatec_smart.h @@ -23,6 +23,7 @@ #define UWATEC_SMART_H #include +#include #include #include @@ -31,7 +32,7 @@ extern "C" { #endif /* __cplusplus */ dc_status_t -uwatec_smart_device_open (dc_device_t **device, dc_context_t *context); +uwatec_smart_device_open (dc_device_t **device, dc_context_t *context, dc_iostream_t *iostream); dc_status_t uwatec_smart_parser_create (dc_parser_t **parser, dc_context_t *context, unsigned int model, unsigned int devtime, dc_ticks_t systime); diff --git a/src/zeagle_n2ition3.c b/src/zeagle_n2ition3.c index 58f81ba..5d0c3bd 100644 --- a/src/zeagle_n2ition3.c +++ b/src/zeagle_n2ition3.c @@ -26,7 +26,6 @@ #include "zeagle_n2ition3.h" #include "context-private.h" #include "device-private.h" -#include "serial.h" #include "checksum.h" #include "array.h" #include "ringbuffer.h" @@ -54,7 +53,6 @@ static dc_status_t zeagle_n2ition3_device_set_fingerprint (dc_device_t *abstract static dc_status_t zeagle_n2ition3_device_read (dc_device_t *abstract, unsigned int address, unsigned char data[], unsigned int size); static dc_status_t zeagle_n2ition3_device_dump (dc_device_t *abstract, dc_buffer_t *buffer); static dc_status_t zeagle_n2ition3_device_foreach (dc_device_t *abstract, dc_dive_callback_t callback, void *userdata); -static dc_status_t zeagle_n2ition3_device_close (dc_device_t *abstract); static const dc_device_vtable_t zeagle_n2ition3_device_vtable = { sizeof(zeagle_n2ition3_device_t), @@ -65,7 +63,7 @@ static const dc_device_vtable_t zeagle_n2ition3_device_vtable = { zeagle_n2ition3_device_dump, /* dump */ zeagle_n2ition3_device_foreach, /* foreach */ NULL, /* timesync */ - zeagle_n2ition3_device_close /* close */ + NULL /* close */ }; @@ -133,7 +131,7 @@ zeagle_n2ition3_init (zeagle_n2ition3_device_t *device) } dc_status_t -zeagle_n2ition3_device_open (dc_device_t **out, dc_context_t *context, const char *name) +zeagle_n2ition3_device_open (dc_device_t **out, dc_context_t *context, dc_iostream_t *iostream) { dc_status_t status = DC_STATUS_SUCCESS; zeagle_n2ition3_device_t *device = NULL; @@ -149,28 +147,21 @@ zeagle_n2ition3_device_open (dc_device_t **out, dc_context_t *context, const cha } // Set the default values. - device->iostream = NULL; + device->iostream = iostream; 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). status = dc_iostream_configure (device->iostream, 4800, 8, DC_PARITY_NONE, DC_STOPBITS_ONE, DC_FLOWCONTROL_NONE); if (status != DC_STATUS_SUCCESS) { ERROR (context, "Failed to set the terminal attributes."); - goto error_close; + goto error_free; } // Set the timeout for receiving data (1000 ms). status = dc_iostream_set_timeout (device->iostream, 1000); if (status != DC_STATUS_SUCCESS) { ERROR (context, "Failed to set the timeout."); - goto error_close; + goto error_free; } // Make sure everything is in a sane state. @@ -183,31 +174,12 @@ zeagle_n2ition3_device_open (dc_device_t **out, dc_context_t *context, const cha return DC_STATUS_SUCCESS; -error_close: - dc_iostream_close (device->iostream); error_free: dc_device_deallocate ((dc_device_t *) device); return status; } -static dc_status_t -zeagle_n2ition3_device_close (dc_device_t *abstract) -{ - dc_status_t status = DC_STATUS_SUCCESS; - zeagle_n2ition3_device_t *device = (zeagle_n2ition3_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 zeagle_n2ition3_device_set_fingerprint (dc_device_t *abstract, const unsigned char data[], unsigned int size) { diff --git a/src/zeagle_n2ition3.h b/src/zeagle_n2ition3.h index d10daa7..2a0d683 100644 --- a/src/zeagle_n2ition3.h +++ b/src/zeagle_n2ition3.h @@ -23,6 +23,7 @@ #define ZEAGLE_N2ITION3_H #include +#include #include #ifdef __cplusplus @@ -30,7 +31,7 @@ extern "C" { #endif /* __cplusplus */ dc_status_t -zeagle_n2ition3_device_open (dc_device_t **device, dc_context_t *context, const char *name); +zeagle_n2ition3_device_open (dc_device_t **device, dc_context_t *context, dc_iostream_t *iostream); #ifdef __cplusplus }