From 8c3e44aa0c64f32931bad4386b38d6357ee53feb Mon Sep 17 00:00:00 2001 From: Claudiu Olteanu Date: Sat, 27 Jun 2015 15:22:04 +0300 Subject: [PATCH] Implement custom device open method This method can be used by external applications to open a device and to pass their custom implementation for the serial communication. Signed-off-by: Claudiu Olteanu Signed-off-by: Dirk Hohndel --- include/libdivecomputer/device.h | 5 +++++ src/device.c | 22 ++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/include/libdivecomputer/device.h b/include/libdivecomputer/device.h index 7ba4bd6..60590b5 100644 --- a/include/libdivecomputer/device.h +++ b/include/libdivecomputer/device.h @@ -2,6 +2,7 @@ * libdivecomputer * * Copyright (C) 2008 Jef Driesen + * Copyright (C) 2015 Claudiu Olteanu * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -27,6 +28,7 @@ #include "descriptor.h" #include "buffer.h" #include "datetime.h" +#include "custom_serial.h" #ifdef __cplusplus extern "C" { @@ -72,6 +74,9 @@ typedef int (*dc_dive_callback_t) (const unsigned char *data, unsigned int size, dc_status_t dc_device_open (dc_device_t **out, dc_context_t *context, dc_descriptor_t *descriptor, const char *name); +dc_status_t +dc_device_custom_open (dc_device_t **out, dc_context_t *context, dc_descriptor_t *descriptor, dc_serial_t *serial); + dc_family_t dc_device_get_type (dc_device_t *device); diff --git a/src/device.c b/src/device.c index d95585d..257dc75 100644 --- a/src/device.c +++ b/src/device.c @@ -2,6 +2,7 @@ * libdivecomputer * * Copyright (C) 2008 Jef Driesen + * Copyright (C) 2015 Claudiu Olteanu * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -174,6 +175,27 @@ dc_device_open (dc_device_t **out, dc_context_t *context, dc_descriptor_t *descr return rc; } +dc_status_t +dc_device_custom_open (dc_device_t **out, dc_context_t *context, dc_descriptor_t *descriptor, dc_serial_t *serial) +{ + dc_status_t rc = DC_STATUS_SUCCESS; + dc_device_t *device = NULL; + + if (out == NULL || descriptor == NULL || serial == NULL) + return DC_STATUS_INVALIDARGS; + + switch (dc_descriptor_get_type (descriptor)) { + case DC_FAMILY_HW_OSTC3: + rc = hw_ostc3_device_custom_open (&device, context, serial); + break; + default: + return DC_STATUS_INVALIDARGS; + } + + *out = device; + + return rc; +} int dc_device_isinstance (dc_device_t *device, const dc_device_vtable_t *vtable)