Integrate the new I/O interface in the public api
Currently the dive computer backends are responsible for opening (and closing) the underlying I/O stream internally. The consequence is that each backend is hardwired to a specific transport type (e.g. serial, irda or usbhid). In order to remove this dependency and support more than one transport type in the same backend, the opening (and closing) of the I/O stream is moved to the application. The dc_device_open() function is modified to accept a pointer to the I/O stream, instead of a string with the device node (which only makes sense for serial communication). The dive computer backends only depend on the common I/O interface.
This commit is contained in:
parent
30ea13b36b
commit
ef2402eff5
@ -155,6 +155,7 @@ 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)
|
||||
{
|
||||
dc_status_t rc = DC_STATUS_SUCCESS;
|
||||
dc_iostream_t *iostream = NULL;
|
||||
dc_device_t *device = NULL;
|
||||
dc_buffer_t *ofingerprint = NULL;
|
||||
|
||||
@ -163,7 +164,7 @@ download (dc_context_t *context, dc_descriptor_t *descriptor, const char *devnam
|
||||
dc_descriptor_get_vendor (descriptor),
|
||||
dc_descriptor_get_product (descriptor),
|
||||
devname ? devname : "null");
|
||||
rc = dc_device_open (&device, context, descriptor, devname);
|
||||
rc = dc_device_open (&device, context, descriptor, iostream);
|
||||
if (rc != DC_STATUS_SUCCESS) {
|
||||
ERROR ("Error opening the device.");
|
||||
goto cleanup;
|
||||
|
||||
@ -43,6 +43,7 @@ static dc_status_t
|
||||
dump (dc_context_t *context, dc_descriptor_t *descriptor, 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.
|
||||
@ -50,7 +51,7 @@ dump (dc_context_t *context, dc_descriptor_t *descriptor, const char *devname, d
|
||||
dc_descriptor_get_vendor (descriptor),
|
||||
dc_descriptor_get_product (descriptor),
|
||||
devname ? devname : "null");
|
||||
rc = dc_device_open (&device, context, descriptor, devname);
|
||||
rc = dc_device_open (&device, context, descriptor, iostream);
|
||||
if (rc != DC_STATUS_SUCCESS) {
|
||||
ERROR ("Error opening the device.");
|
||||
goto cleanup;
|
||||
|
||||
@ -44,6 +44,7 @@ static dc_status_t
|
||||
fwupdate (dc_context_t *context, dc_descriptor_t *descriptor, 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.
|
||||
@ -51,7 +52,7 @@ fwupdate (dc_context_t *context, dc_descriptor_t *descriptor, const char *devnam
|
||||
dc_descriptor_get_vendor (descriptor),
|
||||
dc_descriptor_get_product (descriptor),
|
||||
devname ? devname : "null");
|
||||
rc = dc_device_open (&device, context, descriptor, devname);
|
||||
rc = dc_device_open (&device, context, descriptor, iostream);
|
||||
if (rc != DC_STATUS_SUCCESS) {
|
||||
ERROR ("Error opening the device.");
|
||||
goto cleanup;
|
||||
|
||||
@ -42,6 +42,7 @@ static dc_status_t
|
||||
doread (dc_context_t *context, dc_descriptor_t *descriptor, 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.
|
||||
@ -49,7 +50,7 @@ doread (dc_context_t *context, dc_descriptor_t *descriptor, const char *devname,
|
||||
dc_descriptor_get_vendor (descriptor),
|
||||
dc_descriptor_get_product (descriptor),
|
||||
devname ? devname : "null");
|
||||
rc = dc_device_open (&device, context, descriptor, devname);
|
||||
rc = dc_device_open (&device, context, descriptor, iostream);
|
||||
if (rc != DC_STATUS_SUCCESS) {
|
||||
ERROR ("Error opening the device.");
|
||||
goto cleanup;
|
||||
|
||||
@ -42,6 +42,7 @@ static dc_status_t
|
||||
do_timesync (dc_context_t *context, dc_descriptor_t *descriptor, 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.
|
||||
@ -49,7 +50,7 @@ do_timesync (dc_context_t *context, dc_descriptor_t *descriptor, const char *dev
|
||||
dc_descriptor_get_vendor (descriptor),
|
||||
dc_descriptor_get_product (descriptor),
|
||||
devname ? devname : "null");
|
||||
rc = dc_device_open (&device, context, descriptor, devname);
|
||||
rc = dc_device_open (&device, context, descriptor, iostream);
|
||||
if (rc != DC_STATUS_SUCCESS) {
|
||||
ERROR ("Error opening the device.");
|
||||
goto cleanup;
|
||||
|
||||
@ -42,6 +42,7 @@ static dc_status_t
|
||||
dowrite (dc_context_t *context, dc_descriptor_t *descriptor, 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.
|
||||
@ -49,7 +50,7 @@ dowrite (dc_context_t *context, dc_descriptor_t *descriptor, const char *devname
|
||||
dc_descriptor_get_vendor (descriptor),
|
||||
dc_descriptor_get_product (descriptor),
|
||||
devname ? devname : "null");
|
||||
rc = dc_device_open (&device, context, descriptor, devname);
|
||||
rc = dc_device_open (&device, context, descriptor, iostream);
|
||||
if (rc != DC_STATUS_SUCCESS) {
|
||||
ERROR ("Error opening the device.");
|
||||
goto cleanup;
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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)
|
||||
{
|
||||
|
||||
@ -23,6 +23,7 @@
|
||||
#define CITIZEN_AQUALAND_H
|
||||
|
||||
#include <libdivecomputer/context.h>
|
||||
#include <libdivecomputer/iostream.h>
|
||||
#include <libdivecomputer/device.h>
|
||||
#include <libdivecomputer/parser.h>
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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)
|
||||
{
|
||||
|
||||
@ -23,6 +23,7 @@
|
||||
#define COCHRAN_COMMANDER_H
|
||||
|
||||
#include <libdivecomputer/context.h>
|
||||
#include <libdivecomputer/iostream.h>
|
||||
#include <libdivecomputer/device.h>
|
||||
#include <libdivecomputer/parser.h>
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
|
||||
@ -23,6 +23,7 @@
|
||||
#define CRESSI_EDY_H
|
||||
|
||||
#include <libdivecomputer/context.h>
|
||||
#include <libdivecomputer/iostream.h>
|
||||
#include <libdivecomputer/device.h>
|
||||
#include <libdivecomputer/parser.h>
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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)
|
||||
{
|
||||
|
||||
@ -23,6 +23,7 @@
|
||||
#define CRESSI_LEONARDO_H
|
||||
|
||||
#include <libdivecomputer/context.h>
|
||||
#include <libdivecomputer/iostream.h>
|
||||
#include <libdivecomputer/device.h>
|
||||
#include <libdivecomputer/parser.h>
|
||||
|
||||
@ -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);
|
||||
|
||||
68
src/device.c
68
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;
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
|
||||
@ -23,6 +23,7 @@
|
||||
#define DIVERITE_NITEKQ_H
|
||||
|
||||
#include <libdivecomputer/context.h>
|
||||
#include <libdivecomputer/iostream.h>
|
||||
#include <libdivecomputer/device.h>
|
||||
#include <libdivecomputer/parser.h>
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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)
|
||||
{
|
||||
|
||||
@ -23,6 +23,7 @@
|
||||
#define DIVESYSTEM_IDIVE_H
|
||||
|
||||
#include <libdivecomputer/context.h>
|
||||
#include <libdivecomputer/iostream.h>
|
||||
#include <libdivecomputer/device.h>
|
||||
#include <libdivecomputer/parser.h>
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
|
||||
@ -23,6 +23,7 @@
|
||||
#define HW_FROG_H
|
||||
|
||||
#include <libdivecomputer/context.h>
|
||||
#include <libdivecomputer/iostream.h>
|
||||
#include <libdivecomputer/device.h>
|
||||
#include <libdivecomputer/parser.h>
|
||||
#include <libdivecomputer/hw_frog.h>
|
||||
@ -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
|
||||
}
|
||||
|
||||
@ -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)
|
||||
{
|
||||
|
||||
@ -23,6 +23,7 @@
|
||||
#define HW_OSTC_H
|
||||
|
||||
#include <libdivecomputer/context.h>
|
||||
#include <libdivecomputer/iostream.h>
|
||||
#include <libdivecomputer/device.h>
|
||||
#include <libdivecomputer/parser.h>
|
||||
#include <libdivecomputer/hw_ostc.h>
|
||||
@ -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);
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
|
||||
@ -23,6 +23,7 @@
|
||||
#define HW_OSTC3_H
|
||||
|
||||
#include <libdivecomputer/context.h>
|
||||
#include <libdivecomputer/iostream.h>
|
||||
#include <libdivecomputer/device.h>
|
||||
#include <libdivecomputer/parser.h>
|
||||
#include <libdivecomputer/hw_ostc3.h>
|
||||
@ -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);
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
@ -22,8 +22,9 @@
|
||||
#ifndef MARES_COMMON_H
|
||||
#define MARES_COMMON_H
|
||||
|
||||
#include <libdivecomputer/iostream.h>
|
||||
|
||||
#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);
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -23,6 +23,7 @@
|
||||
#define MARES_DARWIN_H
|
||||
|
||||
#include <libdivecomputer/context.h>
|
||||
#include <libdivecomputer/iostream.h>
|
||||
#include <libdivecomputer/device.h>
|
||||
#include <libdivecomputer/parser.h>
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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)
|
||||
{
|
||||
|
||||
@ -23,6 +23,7 @@
|
||||
#define MARES_ICONHD_H
|
||||
|
||||
#include <libdivecomputer/context.h>
|
||||
#include <libdivecomputer/iostream.h>
|
||||
#include <libdivecomputer/device.h>
|
||||
#include <libdivecomputer/parser.h>
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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)
|
||||
{
|
||||
|
||||
@ -23,6 +23,7 @@
|
||||
#define MARES_NEMO_H
|
||||
|
||||
#include <libdivecomputer/context.h>
|
||||
#include <libdivecomputer/iostream.h>
|
||||
#include <libdivecomputer/device.h>
|
||||
#include <libdivecomputer/parser.h>
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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)
|
||||
{
|
||||
|
||||
@ -23,6 +23,7 @@
|
||||
#define MARES_PUCK_H
|
||||
|
||||
#include <libdivecomputer/context.h>
|
||||
#include <libdivecomputer/iostream.h>
|
||||
#include <libdivecomputer/device.h>
|
||||
#include <libdivecomputer/parser.h>
|
||||
|
||||
@ -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
|
||||
}
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
|
||||
@ -23,6 +23,7 @@
|
||||
#define OCEANIC_ATOM2_H
|
||||
|
||||
#include <libdivecomputer/context.h>
|
||||
#include <libdivecomputer/iostream.h>
|
||||
#include <libdivecomputer/device.h>
|
||||
#include <libdivecomputer/parser.h>
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
|
||||
@ -23,6 +23,7 @@
|
||||
#define OCEANIC_VEO250_H
|
||||
|
||||
#include <libdivecomputer/context.h>
|
||||
#include <libdivecomputer/iostream.h>
|
||||
#include <libdivecomputer/device.h>
|
||||
#include <libdivecomputer/parser.h>
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
|
||||
@ -23,6 +23,7 @@
|
||||
#define OCEANIC_VTPRO_H
|
||||
|
||||
#include <libdivecomputer/context.h>
|
||||
#include <libdivecomputer/iostream.h>
|
||||
#include <libdivecomputer/device.h>
|
||||
#include <libdivecomputer/parser.h>
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
|
||||
@ -23,6 +23,7 @@
|
||||
#define REEFNET_SENSUS_H
|
||||
|
||||
#include <libdivecomputer/context.h>
|
||||
#include <libdivecomputer/iostream.h>
|
||||
#include <libdivecomputer/device.h>
|
||||
#include <libdivecomputer/parser.h>
|
||||
#include <libdivecomputer/reefnet_sensus.h>
|
||||
@ -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);
|
||||
|
||||
@ -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)
|
||||
{
|
||||
|
||||
@ -23,6 +23,7 @@
|
||||
#define REEFNET_SENSUSPRO_H
|
||||
|
||||
#include <libdivecomputer/context.h>
|
||||
#include <libdivecomputer/iostream.h>
|
||||
#include <libdivecomputer/device.h>
|
||||
#include <libdivecomputer/parser.h>
|
||||
#include <libdivecomputer/reefnet_sensuspro.h>
|
||||
@ -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);
|
||||
|
||||
@ -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)
|
||||
{
|
||||
|
||||
@ -23,6 +23,7 @@
|
||||
#define REEFNET_SENSUSULTRA_H
|
||||
|
||||
#include <libdivecomputer/context.h>
|
||||
#include <libdivecomputer/iostream.h>
|
||||
#include <libdivecomputer/device.h>
|
||||
#include <libdivecomputer/parser.h>
|
||||
#include <libdivecomputer/reefnet_sensusultra.h>
|
||||
@ -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);
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -22,8 +22,9 @@
|
||||
#ifndef SHEARWATER_COMMON_H
|
||||
#define SHEARWATER_COMMON_H
|
||||
|
||||
#include <libdivecomputer/iostream.h>
|
||||
|
||||
#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);
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
|
||||
@ -23,6 +23,7 @@
|
||||
#define SHEARWATER_PETREL_H
|
||||
|
||||
#include <libdivecomputer/context.h>
|
||||
#include <libdivecomputer/iostream.h>
|
||||
#include <libdivecomputer/device.h>
|
||||
#include <libdivecomputer/parser.h>
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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)
|
||||
{
|
||||
|
||||
@ -23,6 +23,7 @@
|
||||
#define SHEARWATER_PREDATOR_H
|
||||
|
||||
#include <libdivecomputer/context.h>
|
||||
#include <libdivecomputer/iostream.h>
|
||||
#include <libdivecomputer/device.h>
|
||||
#include <libdivecomputer/parser.h>
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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)
|
||||
{
|
||||
|
||||
@ -23,6 +23,7 @@
|
||||
#define SUUNTO_D9_H
|
||||
|
||||
#include <libdivecomputer/context.h>
|
||||
#include <libdivecomputer/iostream.h>
|
||||
#include <libdivecomputer/device.h>
|
||||
#include <libdivecomputer/parser.h>
|
||||
#include <libdivecomputer/suunto_d9.h>
|
||||
@ -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);
|
||||
|
||||
@ -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)
|
||||
{
|
||||
|
||||
@ -23,6 +23,7 @@
|
||||
#define SUUNTO_EON_H
|
||||
|
||||
#include <libdivecomputer/context.h>
|
||||
#include <libdivecomputer/iostream.h>
|
||||
#include <libdivecomputer/device.h>
|
||||
#include <libdivecomputer/parser.h>
|
||||
#include <libdivecomputer/suunto_eon.h>
|
||||
@ -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);
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
@ -23,6 +23,7 @@
|
||||
#define SUUNTO_EONSTEEL_H
|
||||
|
||||
#include <libdivecomputer/context.h>
|
||||
#include <libdivecomputer/iostream.h>
|
||||
#include <libdivecomputer/device.h>
|
||||
#include <libdivecomputer/parser.h>
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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)
|
||||
{
|
||||
|
||||
@ -23,6 +23,7 @@
|
||||
#define SUUNTO_SOLUTION_H
|
||||
|
||||
#include <libdivecomputer/context.h>
|
||||
#include <libdivecomputer/iostream.h>
|
||||
#include <libdivecomputer/device.h>
|
||||
#include <libdivecomputer/parser.h>
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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)
|
||||
{
|
||||
|
||||
@ -23,6 +23,7 @@
|
||||
#define SUUNTO_VYPER_H
|
||||
|
||||
#include <libdivecomputer/context.h>
|
||||
#include <libdivecomputer/iostream.h>
|
||||
#include <libdivecomputer/device.h>
|
||||
#include <libdivecomputer/parser.h>
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -27,11 +27,12 @@ extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#include <libdivecomputer/context.h>
|
||||
#include <libdivecomputer/iostream.h>
|
||||
#include <libdivecomputer/device.h>
|
||||
#include <libdivecomputer/suunto_vyper2.h>
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
@ -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)
|
||||
{
|
||||
|
||||
@ -27,10 +27,11 @@ extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#include <libdivecomputer/context.h>
|
||||
#include <libdivecomputer/iostream.h>
|
||||
#include <libdivecomputer/device.h>
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
@ -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)
|
||||
{
|
||||
|
||||
@ -23,6 +23,7 @@
|
||||
#define UWATEC_G2_H
|
||||
|
||||
#include <libdivecomputer/context.h>
|
||||
#include <libdivecomputer/iostream.h>
|
||||
#include <libdivecomputer/device.h>
|
||||
#include <libdivecomputer/parser.h>
|
||||
|
||||
@ -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
|
||||
}
|
||||
|
||||
@ -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)
|
||||
{
|
||||
|
||||
@ -23,6 +23,7 @@
|
||||
#define UWATEC_MEMOMOUSE_H
|
||||
|
||||
#include <libdivecomputer/context.h>
|
||||
#include <libdivecomputer/iostream.h>
|
||||
#include <libdivecomputer/device.h>
|
||||
#include <libdivecomputer/parser.h>
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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)
|
||||
{
|
||||
|
||||
@ -23,6 +23,7 @@
|
||||
#define UWATEC_MERIDIAN_H
|
||||
|
||||
#include <libdivecomputer/context.h>
|
||||
#include <libdivecomputer/iostream.h>
|
||||
#include <libdivecomputer/device.h>
|
||||
#include <libdivecomputer/parser.h>
|
||||
|
||||
@ -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
|
||||
}
|
||||
|
||||
@ -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)
|
||||
{
|
||||
|
||||
@ -23,6 +23,7 @@
|
||||
#define UWATEC_SMART_H
|
||||
|
||||
#include <libdivecomputer/context.h>
|
||||
#include <libdivecomputer/iostream.h>
|
||||
#include <libdivecomputer/device.h>
|
||||
#include <libdivecomputer/parser.h>
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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)
|
||||
{
|
||||
|
||||
@ -23,6 +23,7 @@
|
||||
#define ZEAGLE_N2ITION3_H
|
||||
|
||||
#include <libdivecomputer/context.h>
|
||||
#include <libdivecomputer/iostream.h>
|
||||
#include <libdivecomputer/device.h>
|
||||
|
||||
#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
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user