+ /* libdivecomputer does negative percentages. */
+ if (*buffer == '-')
+ return;
+ if (cylinder_index < MAX_CYLINDERS)
+ percent(buffer, _fraction);
+}
+
+static void gasmix_nitrogen(char *buffer, void *_gasmix)
+{
+ /* Ignore n2 percentages. There's no value in them. */
+}
+
+static void cylindersize(char *buffer, void *_volume)
+{
+ volume_t *volume = _volume;
+ union int_or_float val;
+
+ switch (integer_or_float(buffer, &val)) {
+ case FLOAT:
+ volume->mliter = val.fp * 1000 + 0.5;
+ break;
+
+ default:
+ printf("Strange volume reading %s\n", buffer);
+ break;
+ }
+ free(buffer);
+}
+
+static void utf8_string(char *buffer, void *_res)
+{
+ *(char **)_res = buffer;
+}
+
+/*
+ * Uemis water_pressure. In centibar. And when converting to
+ * depth, I'm just going to always use saltwater, because I
+ * think "true depth" is just stupid. From a diving standpoint,
+ * "true depth" is pretty much completely pointless, unless
+ * you're doing some kind of underwater surveying work.
+ *
+ * So I give water depths in "pressure depth", always assuming
+ * salt water. So one atmosphere per 10m.
+ */
+static void water_pressure(char *buffer, void *_depth)
+{
+ depth_t *depth = _depth;
+ union int_or_float val;
+ double atm, cm;
+
+ switch (integer_or_float(buffer, &val)) {
+ case FLOAT:
+ if (!val.fp)
+ break;
+ /* cbar to atm */
+ atm = (val.fp / 100) / 1.01325;
+ /*
+ * atm to cm. Why not mm? The precision just isn't
+ * there.
+ */
+ cm = 100 * (atm - 1) + 0.5;
+ if (cm > 0) {
+ depth->mm = 10 * (long)cm;
+ break;
+ }
+ default:
+ fprintf(stderr, "Strange water pressure '%s'\n", buffer);
+ }
+ free(buffer);
+}
+
+#define MATCH(pattern, fn, dest) \
+ match(pattern, strlen(pattern), name, len, fn, buf, dest)
+
+static void get_index(char *buffer, void *_i)
+{
+ int *i = _i;
+ *i = atoi(buffer);
+ free(buffer);
+}
+
+static void centibar(char *buffer, void *_pressure)
+{
+ pressure_t *pressure = _pressure;
+ union int_or_float val;
+
+ switch (integer_or_float(buffer, &val)) {
+ case FLOAT:
+ pressure->mbar = val.fp * 10 + 0.5;
+ break;
+ default:
+ fprintf(stderr, "Strange centibar pressure '%s'\n", buffer);
+ }
+ free(buffer);
+}
+
+static void decicelsius(char *buffer, void *_temp)
+{
+ temperature_t *temp = _temp;
+ union int_or_float val;
+
+ switch (integer_or_float(buffer, &val)) {
+ case FLOAT:
+ temp->mkelvin = (val.fp/10 + 273.15) * 1000 + 0.5;
+ break;
+ default:
+ fprintf(stderr, "Strange julian date: %s", buffer);
+ }
+ free(buffer);
+}
+
+static int uemis_fill_sample(struct sample *sample, const char *name, int len, char *buf)
+{
+ return MATCH(".reading.dive_time", sampletime, &sample->time) ||
+ MATCH(".reading.water_pressure", water_pressure, &sample->depth) ||
+ MATCH(".reading.active_tank", get_index, &sample->cylinderindex) ||
+ MATCH(".reading.tank_pressure", centibar, &sample->cylinderpressure) ||
+ MATCH(".reading.dive_temperature", decicelsius, &sample->temperature) ||
+ 0;