descriptor.h (6190B)
1 /* 2 * libdivecomputer 3 * 4 * Copyright (C) 2012 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_DESCRIPTOR_H 23 #define DC_DESCRIPTOR_H 24 25 #include "common.h" 26 #include "context.h" 27 #include "iterator.h" 28 29 #ifdef __cplusplus 30 extern "C" { 31 #endif /* __cplusplus */ 32 33 /** 34 * Opaque object representing a supported dive computer. 35 */ 36 typedef struct dc_descriptor_t dc_descriptor_t; 37 38 /** 39 * Create an iterator to enumerate the supported dive computers. 40 * 41 * @param[out] iterator A location to store the iterator. 42 * @param[in] context A valid device descriptor. 43 * @returns #DC_STATUS_SUCCESS on success, or another #dc_status_t code 44 * on failure. 45 */ 46 dc_status_t 47 dc_descriptor_iterator_new (dc_iterator_t **iterator, dc_context_t *context); 48 49 /* For backwards compatibility */ 50 #define dc_descriptor_iterator(iterator) dc_descriptor_iterator_new(iterator, NULL) 51 52 /** 53 * Free the device descriptor. 54 * 55 * @param[in] descriptor A valid device descriptor. 56 */ 57 void 58 dc_descriptor_free (dc_descriptor_t *descriptor); 59 60 /** 61 * Get the vendor name of the dive computer. 62 * 63 * @param[in] descriptor A valid device descriptor. 64 * @returns The vendor name of the dive computer on success, or NULL on failure. 65 */ 66 const char * 67 dc_descriptor_get_vendor (const dc_descriptor_t *descriptor); 68 69 /** 70 * Get the product name of the dive computer. 71 * 72 * @param[in] descriptor A valid device descriptor. 73 * @returns The product name of the dive computer on success, or NULL on 74 * failure. 75 */ 76 const char * 77 dc_descriptor_get_product (const dc_descriptor_t *descriptor); 78 79 /** 80 * Get the family type of the dive computer. 81 * 82 * @param[in] descriptor A valid device descriptor. 83 * @returns The family type of the dive computer on success, or DC_FAMILY_NULL 84 * on failure. 85 */ 86 dc_family_t 87 dc_descriptor_get_type (const dc_descriptor_t *descriptor); 88 89 /** 90 * Get the model number of the dive computer. 91 * 92 * @param[in] descriptor A valid device descriptor. 93 * @returns The model number of the dive computer on success, or zero on 94 * failure. 95 */ 96 unsigned int 97 dc_descriptor_get_model (const dc_descriptor_t *descriptor); 98 99 /** 100 * Get all transports supported by the dive computer. 101 * 102 * @param[in] descriptor A valid device descriptor. 103 * @returns A bitmask with all the transports supported by the dive computer on 104 * success, or DC_TRANSPORT_NONE on failure. 105 */ 106 unsigned int 107 dc_descriptor_get_transports (const dc_descriptor_t *descriptor); 108 109 /** 110 * Check if a low-level I/O device matches a supported dive computer. 111 * 112 * @param[in] descriptor A valid device descriptor. 113 * @param[in] transport The transport type of the I/O device. 114 * @param[in] userdata A pointer to a transport specific data structure: 115 * - DC_TRANSPORT_SERIAL: Name of the device node (string) 116 * - DC_TRANSPORT_USB: USB VID/PID (#dc_usb_desc_t) 117 * - DC_TRANSPORT_USBHID: USB VID/PID (#dc_usbhid_desc_t) 118 * - DC_TRANSPORT_IRDA: IrDA device name (string) 119 * - DC_TRANSPORT_BLUETOOTH: Bluetooth device name (string) 120 * - DC_TRANSPORT_BLE: Bluetooth device name (string) 121 * @returns Non-zero if the device matches a supported dive computer, or zero if 122 * there is no match. 123 */ 124 int 125 dc_descriptor_filter (const dc_descriptor_t *descriptor, dc_transport_t transport, const void *userdata); 126 127 /** 128 * Find a descriptor by hardware identifier. 129 * 130 * Some device families share a coarse model number across multiple marketed 131 * products. When a device reports a hardware identifier (via 132 * DC_EVENT_DEVINFO.hw_id), this function can find a more specific 133 * descriptor than the model number alone provides. This is best-effort: 134 * returns NULL if the hardware id is unknown or not in the table. 135 * 136 * The returned descriptor is a direct reference to an internal table entry 137 * and must be released with dc_descriptor_free(), which is safe to call on 138 * such a reference. 139 * 140 * @param[in] family The device family type. 141 * @param[in] hw_id The hardware identifier from DC_EVENT_DEVINFO. 142 * @returns A descriptor on success, or NULL if no match. 143 */ 144 dc_descriptor_t * 145 dc_descriptor_find_by_hw_id (dc_family_t family, unsigned int hw_id); 146 147 /** 148 * Find a descriptor by raw product-name string from the device version packet. 149 * 150 * Some device families (notably Mares Icon HD) share a coarse numeric model 151 * across multiple marketed products but expose a distinguishing product-name 152 * string in their version packet (DC_EVENT_DEVINFO.product_name). This 153 * function maps that raw string to the best-matching descriptor, while the 154 * coarse model number remains authoritative for parser layout selection. 155 * 156 * The mapping is evidence-based and limited to confirmed product-name strings 157 * from the device firmware. Returns NULL for an empty, NULL, or unrecognised 158 * product-name string; callers must fall back to the coarse model descriptor. 159 * 160 * The returned descriptor is a direct reference to an internal table entry 161 * and must be released with dc_descriptor_free(), which is safe to call on 162 * such a reference. 163 * 164 * @param[in] family The device family type. 165 * @param[in] model The coarse model number from DC_EVENT_DEVINFO. 166 * @param[in] product_name The raw product-name string from DC_EVENT_DEVINFO. 167 * @returns A descriptor on success, or NULL if no match. 168 */ 169 dc_descriptor_t * 170 dc_descriptor_find_by_product_name (dc_family_t family, unsigned int model, const char *product_name); 171 172 #ifdef __cplusplus 173 } 174 #endif /* __cplusplus */ 175 #endif /* DC_DESCRIPTOR_H */