device.h (4142B)
1 /* 2 * libdivecomputer 3 * 4 * Copyright (C) 2008 Jef Driesen 5 * 6 * This library is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU Lesser General Public 8 * License as published by the Free Software Foundation; either 9 * version 2.1 of the License, or (at your option) any later version. 10 * 11 * This library is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 * Lesser General Public License for more details. 15 * 16 * You should have received a copy of the GNU Lesser General Public 17 * License along with this library; if not, write to the Free Software 18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 19 * MA 02110-1301 USA 20 */ 21 22 #ifndef DC_DEVICE_H 23 #define DC_DEVICE_H 24 25 #include "common.h" 26 #include "context.h" 27 #include "descriptor.h" 28 #include "iostream.h" 29 #include "buffer.h" 30 #include "datetime.h" 31 32 #ifdef __cplusplus 33 extern "C" { 34 #endif /* __cplusplus */ 35 36 typedef enum dc_event_type_t { 37 DC_EVENT_WAITING = (1 << 0), 38 DC_EVENT_PROGRESS = (1 << 1), 39 DC_EVENT_DEVINFO = (1 << 2), 40 DC_EVENT_CLOCK = (1 << 3), 41 DC_EVENT_VENDOR = (1 << 4) 42 } dc_event_type_t; 43 44 typedef struct dc_device_t dc_device_t; 45 46 typedef struct dc_event_progress_t { 47 unsigned int current; 48 unsigned int maximum; 49 } dc_event_progress_t; 50 51 /* Maximum length of the product_name field in dc_event_devinfo_t, 52 * including the NUL terminator. */ 53 #define DC_DEVINFO_PRODUCT_NAME_SIZE 17 54 55 typedef struct dc_event_devinfo_t { 56 unsigned int model; 57 unsigned int firmware; 58 unsigned int serial; 59 /* Generic hardware identifier, 0 = unknown/not available. 60 * On live download from devices that support it, this is populated 61 * with the device's hardware type identifier (e.g. Shearwater FWID 62 * from RDBI 0x8050). It supplements the coarse model field for 63 * consumer-side sub-model differentiation. Consumers that do not use 64 * this field are unaffected; the model field remains authoritative. */ 65 unsigned int hw_id; 66 /* Raw product-name string from the device's version packet, NUL-terminated. 67 * Empty string when not available or not applicable for this device family. 68 * Populated only on live download; use dc_descriptor_find_by_product_name() 69 * to map this to a refined descriptor. The model field remains the 70 * authoritative parser-layout selector. */ 71 char product_name[DC_DEVINFO_PRODUCT_NAME_SIZE]; 72 } dc_event_devinfo_t; 73 74 typedef struct dc_event_clock_t { 75 unsigned int devtime; 76 dc_ticks_t systime; 77 } dc_event_clock_t; 78 79 typedef struct dc_event_vendor_t { 80 const unsigned char *data; 81 unsigned int size; 82 } dc_event_vendor_t; 83 84 typedef int (*dc_cancel_callback_t) (void *userdata); 85 86 typedef void (*dc_event_callback_t) (dc_device_t *device, dc_event_type_t event, const void *data, void *userdata); 87 88 typedef int (*dc_dive_callback_t) (const unsigned char *data, unsigned int size, const unsigned char *fingerprint, unsigned int fsize, void *userdata); 89 90 dc_status_t 91 dc_device_open (dc_device_t **out, dc_context_t *context, dc_descriptor_t *descriptor, dc_iostream_t *iostream); 92 93 dc_family_t 94 dc_device_get_type (dc_device_t *device); 95 96 dc_status_t 97 dc_device_set_cancel (dc_device_t *device, dc_cancel_callback_t callback, void *userdata); 98 99 dc_status_t 100 dc_device_set_events (dc_device_t *device, unsigned int events, dc_event_callback_t callback, void *userdata); 101 102 dc_status_t 103 dc_device_set_fingerprint (dc_device_t *device, const unsigned char data[], unsigned int size); 104 105 dc_status_t 106 dc_device_read (dc_device_t *device, unsigned int address, unsigned char data[], unsigned int size); 107 108 dc_status_t 109 dc_device_write (dc_device_t *device, unsigned int address, const unsigned char data[], unsigned int size); 110 111 dc_status_t 112 dc_device_dump (dc_device_t *device, dc_buffer_t *buffer); 113 114 dc_status_t 115 dc_device_foreach (dc_device_t *device, dc_dive_callback_t callback, void *userdata); 116 117 dc_status_t 118 dc_device_timesync (dc_device_t *device, const dc_datetime_t *datetime); 119 120 dc_status_t 121 dc_device_close (dc_device_t *device); 122 123 #ifdef __cplusplus 124 } 125 #endif /* __cplusplus */ 126 #endif /* DC_DEVICE_H */