parser.h (11432B)
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_PARSER_H 23 #define DC_PARSER_H 24 25 #include "common.h" 26 #include "context.h" 27 #include "descriptor.h" 28 #include "device.h" 29 #include "datetime.h" 30 31 #ifdef __cplusplus 32 extern "C" { 33 #endif /* __cplusplus */ 34 35 typedef enum dc_sample_type_t { 36 DC_SAMPLE_TIME, 37 DC_SAMPLE_DEPTH, 38 DC_SAMPLE_PRESSURE, 39 DC_SAMPLE_TEMPERATURE, 40 DC_SAMPLE_EVENT, 41 DC_SAMPLE_RBT, 42 DC_SAMPLE_HEARTBEAT, 43 DC_SAMPLE_BEARING, 44 DC_SAMPLE_VENDOR, 45 DC_SAMPLE_SETPOINT, 46 DC_SAMPLE_PPO2, 47 DC_SAMPLE_CNS, 48 DC_SAMPLE_DECO, 49 DC_SAMPLE_GASMIX, 50 DC_SAMPLE_TTS, // time to surface in seconds 51 DC_SAMPLE_LOCATION, 52 } dc_sample_type_t; 53 54 // Make it easy to test support compile-time with "#ifdef DC_SAMPLE_TTS" 55 #define DC_SAMPLE_TTS DC_SAMPLE_TTS 56 // Make it easy to test support compile-time with "#ifdef DC_SAMPLE_LOCATION" 57 #define DC_SAMPLE_LOCATION DC_SAMPLE_LOCATION 58 59 typedef enum dc_field_type_t { 60 DC_FIELD_DIVETIME, 61 DC_FIELD_MAXDEPTH, 62 DC_FIELD_AVGDEPTH, 63 DC_FIELD_GASMIX_COUNT, 64 DC_FIELD_GASMIX, 65 DC_FIELD_SALINITY, 66 DC_FIELD_ATMOSPHERIC, 67 DC_FIELD_TEMPERATURE_SURFACE, 68 DC_FIELD_TEMPERATURE_MINIMUM, 69 DC_FIELD_TEMPERATURE_MAXIMUM, 70 DC_FIELD_TANK_COUNT, 71 DC_FIELD_TANK, 72 DC_FIELD_DIVEMODE, 73 DC_FIELD_DECOMODEL, 74 DC_FIELD_STRING, 75 DC_FIELD_LOCATION, 76 } dc_field_type_t; 77 78 // Make it easy to test support compile-time with "#ifdef DC_FIELD_STRING" 79 #define DC_FIELD_STRING DC_FIELD_STRING 80 81 typedef enum parser_sample_event_t { 82 SAMPLE_EVENT_NONE, 83 SAMPLE_EVENT_DECOSTOP, 84 SAMPLE_EVENT_RBT, 85 SAMPLE_EVENT_ASCENT, 86 SAMPLE_EVENT_CEILING, 87 SAMPLE_EVENT_WORKLOAD, 88 SAMPLE_EVENT_TRANSMITTER, 89 SAMPLE_EVENT_VIOLATION, 90 SAMPLE_EVENT_BOOKMARK, 91 SAMPLE_EVENT_SURFACE, 92 SAMPLE_EVENT_SAFETYSTOP, 93 SAMPLE_EVENT_GASCHANGE, /* Deprecated: replaced by DC_SAMPLE_GASMIX. */ 94 SAMPLE_EVENT_SAFETYSTOP_VOLUNTARY, 95 SAMPLE_EVENT_SAFETYSTOP_MANDATORY, 96 SAMPLE_EVENT_DEEPSTOP, 97 SAMPLE_EVENT_CEILING_SAFETYSTOP, 98 SAMPLE_EVENT_FLOOR, 99 SAMPLE_EVENT_DIVETIME, 100 SAMPLE_EVENT_MAXDEPTH, 101 SAMPLE_EVENT_OLF, 102 SAMPLE_EVENT_PO2, 103 SAMPLE_EVENT_AIRTIME, 104 SAMPLE_EVENT_RGBM, 105 SAMPLE_EVENT_HEADING, /* Deprecated: replaced by DC_SAMPLE_BEARING. */ 106 SAMPLE_EVENT_TISSUELEVEL, 107 SAMPLE_EVENT_GASCHANGE2, /* Deprecated: replaced by DC_SAMPLE_GASMIX. */ 108 SAMPLE_EVENT_STRING, 109 } parser_sample_event_t; 110 111 /* To let the compile know we have this */ 112 #define SAMPLE_EVENT_STRING SAMPLE_EVENT_STRING 113 114 #define STRING_KEY_FIRMWARE_VERSION "FW Version" 115 #define STRING_KEY_SERIAL_NUMBER "Serial" 116 117 /* For backwards compatibility */ 118 #define SAMPLE_EVENT_UNKNOWN SAMPLE_EVENT_FLOOR 119 120 typedef enum parser_sample_flags_t { 121 SAMPLE_FLAGS_NONE = 0, 122 SAMPLE_FLAGS_BEGIN = (1 << 0), 123 SAMPLE_FLAGS_END = (1 << 1), 124 SAMPLE_FLAGS_SEVERITY_MASK = (7 << 2), 125 } parser_sample_flags_t; 126 127 #define SAMPLE_FLAGS_SEVERITY_SHIFT 2 128 129 #define SAMPLE_FLAGS_SEVERITY_MISSING (0 << SAMPLE_FLAGS_SEVERITY_SHIFT) 130 #define SAMPLE_FLAGS_SEVERITY_STATE (1 << SAMPLE_FLAGS_SEVERITY_SHIFT) 131 #define SAMPLE_FLAGS_SEVERITY_INFO (2 << SAMPLE_FLAGS_SEVERITY_SHIFT) 132 #define SAMPLE_FLAGS_SEVERITY_WARN (3 << SAMPLE_FLAGS_SEVERITY_SHIFT) 133 #define SAMPLE_FLAGS_SEVERITY_ALARM (4 << SAMPLE_FLAGS_SEVERITY_SHIFT) 134 135 /* these are used for the types of TAGs in Shearwater PNF info events */ 136 #define SAMPLE_FLAGS_TYPE_SHIFT 5 137 #define SAMPLE_FLAGS_TYPE_MASK (7 << SAMPLE_FLAGS_TYPE_SHIFT) 138 #define SAMPLE_FLAGS_TYPE_NONE (0 << SAMPLE_FLAGS_TYPE_SHIFT) 139 #define SAMPLE_FLAGS_TYPE_INTEREST (1 << SAMPLE_FLAGS_TYPE_SHIFT) 140 #define SAMPLE_FLAGS_TYPE_NAVPOINT (2 << SAMPLE_FLAGS_TYPE_SHIFT) 141 #define SAMPLE_FLAGS_TYPE_DANGER (3 << SAMPLE_FLAGS_TYPE_SHIFT) 142 #define SAMPLE_FLAGS_TYPE_ANIMAL (4 << SAMPLE_FLAGS_TYPE_SHIFT) 143 #define SAMPLE_FLAGS_TYPE_ISSUE (5 << SAMPLE_FLAGS_TYPE_SHIFT) 144 #define SAMPLE_FLAGS_TYPE_INJURY (6 << SAMPLE_FLAGS_TYPE_SHIFT) 145 146 typedef enum parser_sample_vendor_t { 147 SAMPLE_VENDOR_NONE, 148 SAMPLE_VENDOR_UWATEC_ALADIN, 149 SAMPLE_VENDOR_UWATEC_SMART, 150 SAMPLE_VENDOR_OCEANIC_VTPRO, 151 SAMPLE_VENDOR_OCEANIC_VEO250, 152 SAMPLE_VENDOR_OCEANIC_ATOM2 153 } parser_sample_vendor_t; 154 155 typedef enum dc_water_t { 156 DC_WATER_FRESH, 157 DC_WATER_SALT 158 } dc_water_t; 159 160 typedef enum dc_divemode_t { 161 DC_DIVEMODE_FREEDIVE, 162 DC_DIVEMODE_GAUGE, 163 DC_DIVEMODE_OC, /* Open circuit */ 164 DC_DIVEMODE_CCR, /* Closed circuit rebreather */ 165 DC_DIVEMODE_SCR /* Semi-closed circuit rebreather */ 166 } dc_divemode_t; 167 168 /* For backwards compatibility */ 169 #define DC_DIVEMODE_CC DC_DIVEMODE_CCR 170 171 typedef enum dc_deco_type_t { 172 DC_DECO_NDL, 173 DC_DECO_SAFETYSTOP, 174 DC_DECO_DECOSTOP, 175 DC_DECO_DEEPSTOP 176 } dc_deco_type_t; 177 178 typedef struct dc_salinity_t { 179 dc_water_t type; 180 double density; 181 } dc_salinity_t; 182 183 typedef enum dc_usage_t { 184 DC_USAGE_NONE, // Usage not specified 185 DC_USAGE_OXYGEN, 186 DC_USAGE_DILUENT, 187 DC_USAGE_OPEN_CIRCUIT, 188 } dc_usage_t; 189 190 typedef struct dc_gasmix_t { 191 double helium; 192 double oxygen; 193 double nitrogen; 194 dc_usage_t usage; 195 } dc_gasmix_t; 196 197 #define DC_SENSOR_NONE 0xFFFFFFFF 198 #define DC_GASMIX_UNKNOWN 0xFFFFFFFF 199 200 typedef unsigned int dc_tankinfo_t; 201 #define DC_TANKINFO_METRIC 1 202 #define DC_TANKINFO_IMPERIAL 2 203 204 // For backwards compatibility 205 #define DC_TANKVOLUME_NONE 0 206 #define DC_TANKVOLUME_METRIC DC_TANKINFO_METRIC 207 #define DC_TANKVOLUME_IMPERIAL DC_TANKINFO_IMPERIAL 208 209 /* 210 * Tank volume 211 * 212 * There are two different ways to specify the volume of a tank. In the 213 * metric system, the tank volume is specified as the water capacity, 214 * while in the imperial system the tank volume is specified as the air 215 * capacity at the surface (1 ATM) when the tank is filled at its 216 * working pressure. Libdivecomputer will always convert the tank volume 217 * to the metric representation, and indicate the original tank type: 218 * 219 * DC_TANKVOLUME_NONE: Tank volume is not available. Both the volume and 220 * workpressure will be zero. 221 * 222 * DC_TANKVOLUME_METRIC: A metric tank. The workpressure is optional and 223 * may be zero. 224 * 225 * DC_TANKVOLUME_IMPERIAL: An imperial tank. Both the volume and 226 * workpressure are mandatory and always non-zero. The volume has been 227 * converted from air capacity to water capacity. To calculate the 228 * original air capacity again, multiply with the workpressure and 229 * divide by 1 ATM (Vair = Vwater * Pwork / Patm). 230 */ 231 232 typedef enum dc_tank_usage_t { 233 DC_TANK_USAGE_NONE, /* Not specified, or unknown. */ 234 DC_TANK_USAGE_SIDEMOUNT, 235 DC_TANK_USAGE_INCLUDED, /* The dive computer counts this tank towards 236 the diver's own gas consumption. */ 237 DC_TANK_USAGE_EXCLUDED, /* The dive computer does not count this tank 238 towards the diver's own gas consumption 239 (for example a buddy's or a stage/deco 240 bottle that is tracked but not included). */ 241 } dc_tank_usage_t; 242 243 typedef struct dc_tank_t { 244 unsigned int gasmix; /* Gas mix index, or DC_GASMIX_UNKNOWN */ 245 dc_tankinfo_t type; /* Tank type - metric/imperial and oc/cc */ 246 double volume; /* Volume (liter) */ 247 double workpressure; /* Work pressure (bar) */ 248 double beginpressure; /* Begin pressure (bar) */ 249 double endpressure; /* End pressure (bar) */ 250 dc_tank_usage_t usage; 251 } dc_tank_t; 252 253 typedef enum dc_decomodel_type_t { 254 DC_DECOMODEL_NONE, 255 DC_DECOMODEL_BUHLMANN, 256 DC_DECOMODEL_VPM, 257 DC_DECOMODEL_RGBM, 258 DC_DECOMODEL_DCIEM, 259 } dc_decomodel_type_t; 260 261 /* 262 * Decompression model 263 * 264 * The type field contains the decompression algorithm. 265 * 266 * The (optional) conservatism field contains the personal adjustment 267 * setting of the algorithm. The exact interpretation depends on the 268 * dive computer, but the default value (zero) will typically correspond 269 * to the neutral setting, while a positive value is more conservative 270 * and a negative value more aggressive. 271 * 272 * The (optional) params field contains the parameters of the algorithm: 273 * 274 * DC_DECOMODEL_BUHLMANN: The Gradient Factor (GF) parameters low and 275 * high. For a pure Buhlmann algorithm (e.g. without GF enabled), both 276 * values are 100. If GF are enabled, but the actual parameter values 277 * are not available from the dive computer, both values are zero. 278 */ 279 typedef struct dc_decomodel_t { 280 dc_decomodel_type_t type; 281 int conservatism; 282 union { 283 struct { 284 unsigned int high; 285 unsigned int low; 286 } gf; 287 } params; 288 } dc_decomodel_t; 289 290 typedef struct dc_field_string_t { 291 const char *desc; 292 const char *value; 293 } dc_field_string_t; 294 295 /* 296 * GPS Location 297 * 298 * The latitude and longitude are in decimal degrees, and the (optional) 299 * altitude in meters. 300 */ 301 typedef struct dc_location_t { 302 double latitude; 303 double longitude; 304 double altitude; 305 } dc_location_t; 306 307 typedef union dc_sample_value_t { 308 unsigned int time; /* Milliseconds */ 309 double depth; 310 struct { 311 unsigned int tank; 312 double value; 313 } pressure; 314 double temperature; 315 struct { 316 unsigned int type; 317 unsigned int time; 318 unsigned int flags; 319 unsigned int value; 320 const char *name; 321 } event; 322 unsigned int rbt; 323 unsigned int heartbeat; 324 unsigned int bearing; 325 struct { 326 unsigned int type; 327 unsigned int size; 328 const void *data; 329 } vendor; 330 double setpoint; 331 struct { 332 unsigned int sensor; 333 double value; 334 } ppo2; 335 double cns; 336 struct { 337 unsigned int type; 338 unsigned int time; 339 double depth; 340 unsigned int tts; 341 } deco; 342 unsigned int gasmix; /* Gas mix index */ 343 dc_location_t location; 344 } dc_sample_value_t; 345 346 typedef struct dc_parser_t dc_parser_t; 347 348 typedef void (*dc_sample_callback_t) (dc_sample_type_t type, const dc_sample_value_t *value, void *userdata); 349 350 dc_status_t 351 dc_parser_new (dc_parser_t **parser, dc_device_t *device, const unsigned char data[], size_t size); 352 353 dc_status_t 354 dc_parser_new2 (dc_parser_t **parser, dc_context_t *context, dc_descriptor_t *descriptor, const unsigned char data[], size_t size); 355 356 dc_family_t 357 dc_parser_get_type (dc_parser_t *parser); 358 359 dc_status_t 360 dc_parser_set_clock (dc_parser_t *parser, unsigned int devtime, dc_ticks_t systime); 361 362 dc_status_t 363 dc_parser_set_atmospheric (dc_parser_t *parser, double atmospheric); 364 365 dc_status_t 366 dc_parser_set_density (dc_parser_t *parser, double density); 367 368 dc_status_t 369 dc_parser_get_datetime (dc_parser_t *parser, dc_datetime_t *datetime); 370 371 /* Returns parser-provided device information when available. */ 372 dc_status_t 373 dc_parser_get_device_info (dc_parser_t *parser, dc_event_devinfo_t *devinfo); 374 375 /* DC_FIELD_STRING values are caller-owned and must be freed after use. */ 376 dc_status_t 377 dc_parser_get_field (dc_parser_t *parser, dc_field_type_t type, unsigned int flags, void *value); 378 379 dc_status_t 380 dc_parser_samples_foreach (dc_parser_t *parser, dc_sample_callback_t callback, void *userdata); 381 382 dc_status_t 383 dc_parser_destroy (dc_parser_t *parser); 384 385 #ifdef __cplusplus 386 } 387 #endif /* __cplusplus */ 388 #endif /* DC_PARSER_H */