field-cache.h (2062B)
1 #include <string.h> 2 3 #define MAXGASES 16 4 #define MAXSTRINGS 32 5 6 // dc_get_field() data 7 typedef struct dc_field_cache { 8 unsigned int initialized; 9 10 // DC_GET_FIELD_xyz 11 unsigned int DIVETIME; 12 double MAXDEPTH; 13 double AVGDEPTH; 14 double ATMOSPHERIC; 15 dc_divemode_t DIVEMODE; 16 unsigned int GASMIX_COUNT; 17 unsigned int TANK_COUNT; 18 dc_salinity_t SALINITY; 19 dc_gasmix_t GASMIX[MAXGASES]; 20 21 // misc - clean me up! 22 double lowsetpoint; 23 double highsetpoint; 24 double customsetpoint; 25 26 // This (along with GASMIX) should be something like 27 // dc_tank_t TANK[MAXGASES] 28 // but that's for later 29 dc_tankinfo_t tankinfo[MAXGASES]; 30 dc_tank_usage_t tankusage[MAXGASES]; 31 double tanksize[MAXGASES]; 32 double tankworkingpressure[MAXGASES]; 33 34 // DC_GET_FIELD_STRING 35 dc_field_string_t strings[MAXSTRINGS]; 36 } dc_field_cache_t; 37 38 dc_status_t dc_field_add_string(dc_field_cache_t *, const char *desc, const char *data); 39 dc_status_t dc_field_add_string_fmt(dc_field_cache_t *, const char *desc, const char *fmt, ...); 40 dc_status_t dc_field_get_string(dc_field_cache_t *, unsigned idx, dc_field_string_t *value); 41 dc_status_t dc_field_get(dc_field_cache_t *, dc_field_type_t, unsigned int, void *); 42 void dc_field_cache_free (dc_field_cache_t *); 43 44 /* 45 * Macro to make it easy to set DC_FIELD_xyz values. 46 * 47 * This explains why dc_field_cache member names are 48 * those odd all-capitalized names: they match the 49 * names of the DC_FIELD_xyz enums. 50 */ 51 #define DC_ASSIGN_FIELD(cache, name, value) do { \ 52 (cache).initialized |= 1u << DC_FIELD_##name; \ 53 (cache).name = (value); \ 54 } while (0) 55 56 #define DC_ASSIGN_IDX(cache, name, idx, value) do { \ 57 (cache).initialized |= 1u << DC_FIELD_##name; \ 58 (cache).name[idx] = (value); \ 59 } while (0) 60 61 // Ugly define thing makes the code much easier to read 62 // I'd love to use __typeof__, but that's a gcc'ism 63 #define DC_FIELD_VALUE(cache, p, NAME) \ 64 (memcpy((p), &(cache).NAME, sizeof((cache).NAME)), DC_STATUS_SUCCESS) 65 66 #define DC_FIELD_INDEX(cache, p, NAME, idx) \ 67 (memcpy((p), (cache).NAME+idx, sizeof((cache).NAME[0])), DC_STATUS_SUCCESS)