2017-04-27 18:18:03 +00:00
|
|
|
// SPDX-License-Identifier: MIT
|
2011-09-15 04:00:49 +00:00
|
|
|
/*
|
|
|
|
* uemis.c
|
|
|
|
*
|
|
|
|
* UEMIS SDA file importer
|
|
|
|
* AUTHOR: Dirk Hohndel - Copyright 2011
|
|
|
|
*
|
|
|
|
* Licensed under the MIT license.
|
|
|
|
*/
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
2023-12-03 21:59:21 +00:00
|
|
|
#include <stdlib.h>
|
2013-10-06 15:55:58 +00:00
|
|
|
|
|
|
|
#include "gettext.h"
|
2011-09-15 04:00:49 +00:00
|
|
|
|
|
|
|
#include "uemis.h"
|
2024-04-23 14:09:52 +00:00
|
|
|
#include "dive.h"
|
|
|
|
#include "divecomputer.h"
|
2019-03-04 22:20:29 +00:00
|
|
|
#include "divesite.h"
|
2024-03-24 20:03:08 +00:00
|
|
|
#include "errorhelper.h"
|
2024-05-18 19:04:58 +00:00
|
|
|
#include "format.h"
|
2020-10-25 12:28:55 +00:00
|
|
|
#include "sample.h"
|
2012-11-10 08:28:02 +00:00
|
|
|
#include <libdivecomputer/parser.h>
|
2012-11-29 04:13:21 +00:00
|
|
|
#include <libdivecomputer/version.h>
|
2011-09-15 04:00:49 +00:00
|
|
|
|
2024-04-23 14:09:52 +00:00
|
|
|
struct uemis_sample
|
|
|
|
{
|
|
|
|
uint16_t dive_time;
|
|
|
|
uint16_t water_pressure; // (in cbar)
|
|
|
|
uint16_t dive_temperature; // (in dC)
|
|
|
|
uint8_t ascent_speed; // (units unclear)
|
|
|
|
uint8_t work_fact;
|
|
|
|
uint8_t cold_fact;
|
|
|
|
uint8_t bubble_fact;
|
|
|
|
uint16_t ascent_time;
|
|
|
|
uint16_t ascent_time_opt;
|
|
|
|
uint16_t p_amb_tol;
|
|
|
|
uint16_t satt;
|
|
|
|
uint16_t hold_depth;
|
|
|
|
uint16_t hold_time;
|
|
|
|
uint8_t active_tank;
|
|
|
|
// bloody glib, when compiled for Windows, forces the whole program to use
|
|
|
|
// the Windows packing rules. So to avoid problems on Windows (and since
|
|
|
|
// only tank_pressure is currently used and that exactly once) I give in and
|
|
|
|
// make this silly low byte / high byte 8bit entries
|
|
|
|
uint8_t tank_pressure_low; // (in cbar)
|
|
|
|
uint8_t tank_pressure_high;
|
|
|
|
uint8_t consumption_low; // (units unclear)
|
|
|
|
uint8_t consumption_high;
|
|
|
|
uint8_t rgt; // (remaining gas time in minutes)
|
|
|
|
uint8_t cns;
|
|
|
|
uint8_t flags[8];
|
|
|
|
} __attribute((packed));
|
|
|
|
|
2011-09-15 04:00:49 +00:00
|
|
|
/*
|
|
|
|
* following code is based on code found in at base64.sourceforge.net/b64.c
|
|
|
|
* AUTHOR: Bob Trower 08/04/01
|
|
|
|
* COPYRIGHT: Copyright (c) Trantor Standard Systems Inc., 2001
|
|
|
|
* NOTE: This source code may be used as you wish, subject to
|
|
|
|
* the MIT license.
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
* Translation Table to decode (created by Bob Trower)
|
|
|
|
*/
|
2014-02-28 04:09:57 +00:00
|
|
|
static const char cd64[] = "|$$$}rstuvwxyz{$$$$$$$>?@ABCDEFGHIJKLMNOPQRSTUVW$$$$$$XYZ[\\]^_`abcdefghijklmnopq";
|
2011-09-15 04:00:49 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* decodeblock -- decode 4 '6-bit' characters into 3 8-bit binary bytes
|
|
|
|
*/
|
2014-02-28 04:09:57 +00:00
|
|
|
static void decodeblock(unsigned char in[4], unsigned char out[3])
|
|
|
|
{
|
|
|
|
out[0] = (unsigned char)(in[0] << 2 | in[1] >> 4);
|
|
|
|
out[1] = (unsigned char)(in[1] << 4 | in[2] >> 2);
|
|
|
|
out[2] = (unsigned char)(((in[2] << 6) & 0xc0) | in[3]);
|
2011-09-15 04:00:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* decode a base64 encoded stream discarding padding, line breaks and noise
|
|
|
|
*/
|
2014-02-28 04:09:57 +00:00
|
|
|
static void decode(uint8_t *inbuf, uint8_t *outbuf, int inbuf_len)
|
|
|
|
{
|
2011-09-15 04:00:49 +00:00
|
|
|
uint8_t in[4], out[3], v;
|
2014-02-28 04:09:57 +00:00
|
|
|
int i, len, indx_in = 0, indx_out = 0;
|
2011-09-15 04:00:49 +00:00
|
|
|
|
|
|
|
while (indx_in < inbuf_len) {
|
2013-01-29 21:10:46 +00:00
|
|
|
for (len = 0, i = 0; i < 4 && (indx_in < inbuf_len); i++) {
|
2011-09-15 04:00:49 +00:00
|
|
|
v = 0;
|
|
|
|
while ((indx_in < inbuf_len) && v == 0) {
|
|
|
|
v = inbuf[indx_in++];
|
2014-02-28 04:09:57 +00:00
|
|
|
v = ((v < 43 || v > 122) ? 0 : cd64[v - 43]);
|
2011-09-15 04:00:49 +00:00
|
|
|
if (v)
|
|
|
|
v = ((v == '$') ? 0 : v - 61);
|
|
|
|
}
|
|
|
|
if (indx_in < inbuf_len) {
|
|
|
|
len++;
|
|
|
|
if (v)
|
|
|
|
in[i] = (v - 1);
|
2014-02-28 04:09:57 +00:00
|
|
|
} else
|
2011-09-15 04:00:49 +00:00
|
|
|
in[i] = 0;
|
|
|
|
}
|
2013-01-29 21:10:46 +00:00
|
|
|
if (len) {
|
|
|
|
decodeblock(in, out);
|
2014-02-28 04:09:57 +00:00
|
|
|
for (i = 0; i < len - 1; i++)
|
2011-09-15 04:00:49 +00:00
|
|
|
outbuf[indx_out++] = out[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* end code from Bob Trower */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* convert the base64 data blog
|
|
|
|
*/
|
2024-04-29 05:02:54 +00:00
|
|
|
static std::vector<uint8_t> convert_base64(std::string_view base64)
|
2014-02-28 04:09:57 +00:00
|
|
|
{
|
2024-04-29 05:02:54 +00:00
|
|
|
int datalen;
|
|
|
|
int len = (int)base64.size();
|
2011-09-15 04:00:49 +00:00
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
datalen = (len / 4 + 1) * 3;
|
2015-09-18 19:35:35 +00:00
|
|
|
if (datalen < 0x123 + 0x25)
|
2011-09-15 04:00:49 +00:00
|
|
|
/* less than header + 1 sample??? */
|
2024-03-24 20:03:08 +00:00
|
|
|
report_info("suspiciously short data block %d", datalen);
|
2015-09-18 19:35:35 +00:00
|
|
|
|
2024-04-23 14:09:52 +00:00
|
|
|
std::vector<uint8_t> res(datalen);
|
2024-04-29 05:02:54 +00:00
|
|
|
decode((unsigned char *)base64.begin(), res.data(), len);
|
2011-09-15 04:00:49 +00:00
|
|
|
|
2024-04-23 14:09:52 +00:00
|
|
|
if (memcmp(res.data(), "Dive\01\00\00", 7))
|
2024-03-24 20:03:08 +00:00
|
|
|
report_info("Missing Dive100 header");
|
2011-09-15 04:00:49 +00:00
|
|
|
|
2024-04-23 14:09:52 +00:00
|
|
|
return res;
|
2011-09-15 04:00:49 +00:00
|
|
|
}
|
|
|
|
|
2024-04-23 14:09:52 +00:00
|
|
|
struct uemis::helper &uemis::get_helper(uint32_t diveid)
|
2012-11-29 00:11:19 +00:00
|
|
|
{
|
2024-04-23 14:09:52 +00:00
|
|
|
return helper_table[diveid];
|
2012-11-29 00:11:19 +00:00
|
|
|
}
|
|
|
|
|
2024-04-23 14:09:52 +00:00
|
|
|
void uemis::weight_unit(int diveid, int lbs)
|
2012-11-29 00:11:19 +00:00
|
|
|
{
|
2024-04-23 14:09:52 +00:00
|
|
|
struct uemis::helper &hp = get_helper(diveid);
|
|
|
|
hp.lbs = lbs;
|
2012-11-29 00:11:19 +00:00
|
|
|
}
|
|
|
|
|
2024-04-23 14:09:52 +00:00
|
|
|
int uemis::get_weight_unit(uint32_t diveid) const
|
2012-11-29 00:11:19 +00:00
|
|
|
{
|
2024-04-23 14:09:52 +00:00
|
|
|
auto it = helper_table.find(diveid);
|
|
|
|
return it != helper_table.end() ? it->second.lbs : 0;
|
2012-11-29 00:11:19 +00:00
|
|
|
}
|
|
|
|
|
2024-04-23 14:09:52 +00:00
|
|
|
void uemis::mark_divelocation(int diveid, int divespot, struct dive_site *ds)
|
2012-11-29 00:11:19 +00:00
|
|
|
{
|
2024-04-23 14:09:52 +00:00
|
|
|
struct uemis::helper &hp = get_helper(diveid);
|
|
|
|
hp.divespot = divespot;
|
|
|
|
hp.dive_site = ds;
|
2012-11-29 00:11:19 +00:00
|
|
|
}
|
|
|
|
|
2015-09-10 14:05:16 +00:00
|
|
|
/* support finding a dive spot based on the diveid */
|
2024-04-23 14:09:52 +00:00
|
|
|
int uemis::get_divespot_id_by_diveid(uint32_t diveid) const
|
2015-09-10 14:05:16 +00:00
|
|
|
{
|
2024-04-23 14:09:52 +00:00
|
|
|
auto it = helper_table.find(diveid);
|
|
|
|
return it != helper_table.end() ? it->second.divespot : -1;
|
2015-09-10 14:05:16 +00:00
|
|
|
}
|
|
|
|
|
2024-04-29 05:02:54 +00:00
|
|
|
void uemis::set_divelocation(int divespot, const std::string &text, double longitude, double latitude)
|
2012-11-29 00:11:19 +00:00
|
|
|
{
|
2024-04-23 14:09:52 +00:00
|
|
|
for (auto it: helper_table) {
|
|
|
|
if (it.second.divespot == divespot) {
|
|
|
|
struct dive_site *ds = it.second.dive_site;
|
2015-09-10 18:54:03 +00:00
|
|
|
if (ds) {
|
2024-05-04 15:18:08 +00:00
|
|
|
ds->name = text;
|
2018-10-20 18:12:15 +00:00
|
|
|
ds->location = create_location(latitude, longitude);
|
2015-09-10 18:54:03 +00:00
|
|
|
}
|
2012-11-29 00:11:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-10 08:28:02 +00:00
|
|
|
/* Create events from the flag bits and other data in the sample;
|
2011-10-03 19:27:14 +00:00
|
|
|
* These bits basically represent what is displayed on screen at sample time.
|
|
|
|
* Many of these 'warnings' are way hyper-active and seriously clutter the
|
|
|
|
* profile plot - so these are disabled by default
|
2012-10-21 18:34:11 +00:00
|
|
|
*
|
|
|
|
* we mark all the strings for translation, but we store the untranslated
|
|
|
|
* strings and only convert them when displaying them on screen - this way
|
|
|
|
* when we write them to the XML file we'll always have the English strings,
|
|
|
|
* regardless of locale
|
2011-10-03 19:27:14 +00:00
|
|
|
*/
|
2024-04-23 14:09:52 +00:00
|
|
|
void uemis::event(struct dive *dive, struct divecomputer *dc, struct sample *sample, const uemis_sample *u_sample)
|
2011-10-03 19:27:14 +00:00
|
|
|
{
|
2024-04-23 14:09:52 +00:00
|
|
|
const uint8_t *flags = u_sample->flags;
|
2012-12-05 05:06:54 +00:00
|
|
|
int stopdepth;
|
|
|
|
static int lastndl;
|
2011-10-03 19:27:14 +00:00
|
|
|
|
|
|
|
if (flags[1] & 0x01)
|
2014-11-25 15:47:24 +00:00
|
|
|
add_event(dc, sample->time.seconds, 0, 0, 0, QT_TRANSLATE_NOOP("gettextFromC", "Safety stop violation"));
|
2011-10-03 19:27:14 +00:00
|
|
|
if (flags[1] & 0x08)
|
2014-11-25 15:47:24 +00:00
|
|
|
add_event(dc, sample->time.seconds, 0, 0, 0, QT_TRANSLATE_NOOP("gettextFromC", "Speed alarm"));
|
2011-10-03 19:27:14 +00:00
|
|
|
#if WANT_CRAZY_WARNINGS
|
|
|
|
if (flags[1] & 0x06) /* both bits 1 and 2 are a warning */
|
2014-11-25 15:47:24 +00:00
|
|
|
add_event(dc, sample->time.seconds, 0, 0, 0, QT_TRANSLATE_NOOP("gettextFromC", "Speed warning"));
|
2011-10-03 19:27:14 +00:00
|
|
|
if (flags[1] & 0x10)
|
2014-11-25 15:47:24 +00:00
|
|
|
add_event(dc, sample->time.seconds, 0, 0, 0, QT_TRANSLATE_NOOP("gettextFromC", "pO₂ green warning"));
|
2011-10-03 19:27:14 +00:00
|
|
|
#endif
|
|
|
|
if (flags[1] & 0x20)
|
2014-11-25 15:47:24 +00:00
|
|
|
add_event(dc, sample->time.seconds, 0, 0, 0, QT_TRANSLATE_NOOP("gettextFromC", "pO₂ ascend warning"));
|
2011-10-03 19:27:14 +00:00
|
|
|
if (flags[1] & 0x40)
|
2014-11-25 15:47:24 +00:00
|
|
|
add_event(dc, sample->time.seconds, 0, 0, 0, QT_TRANSLATE_NOOP("gettextFromC", "pO₂ ascend alarm"));
|
2011-10-03 19:27:14 +00:00
|
|
|
/* flags[2] reflects the deco / time bar
|
|
|
|
* flags[3] reflects more display details on deco and pO2 */
|
|
|
|
if (flags[4] & 0x01)
|
2014-11-25 15:47:24 +00:00
|
|
|
add_event(dc, sample->time.seconds, 0, 0, 0, QT_TRANSLATE_NOOP("gettextFromC", "Tank pressure info"));
|
2011-10-03 19:27:14 +00:00
|
|
|
if (flags[4] & 0x04)
|
2014-11-25 15:47:24 +00:00
|
|
|
add_event(dc, sample->time.seconds, 0, 0, 0, QT_TRANSLATE_NOOP("gettextFromC", "RGT warning"));
|
2011-10-03 19:27:14 +00:00
|
|
|
if (flags[4] & 0x08)
|
2014-11-25 15:47:24 +00:00
|
|
|
add_event(dc, sample->time.seconds, 0, 0, 0, QT_TRANSLATE_NOOP("gettextFromC", "RGT alert"));
|
2011-10-03 19:27:14 +00:00
|
|
|
if (flags[4] & 0x40)
|
2014-11-25 15:47:24 +00:00
|
|
|
add_event(dc, sample->time.seconds, 0, 0, 0, QT_TRANSLATE_NOOP("gettextFromC", "Tank change suggested"));
|
2011-10-03 19:27:14 +00:00
|
|
|
if (flags[4] & 0x80)
|
2014-11-25 15:47:24 +00:00
|
|
|
add_event(dc, sample->time.seconds, 0, 0, 0, QT_TRANSLATE_NOOP("gettextFromC", "Depth limit exceeded"));
|
2011-10-03 19:27:14 +00:00
|
|
|
if (flags[5] & 0x01)
|
2014-11-25 15:47:24 +00:00
|
|
|
add_event(dc, sample->time.seconds, 0, 0, 0, QT_TRANSLATE_NOOP("gettextFromC", "Max deco time warning"));
|
2011-10-03 19:27:14 +00:00
|
|
|
if (flags[5] & 0x04)
|
2014-11-25 15:47:24 +00:00
|
|
|
add_event(dc, sample->time.seconds, 0, 0, 0, QT_TRANSLATE_NOOP("gettextFromC", "Dive time info"));
|
2011-10-03 19:27:14 +00:00
|
|
|
if (flags[5] & 0x08)
|
2014-11-25 15:47:24 +00:00
|
|
|
add_event(dc, sample->time.seconds, 0, 0, 0, QT_TRANSLATE_NOOP("gettextFromC", "Dive time alert"));
|
2011-10-03 19:27:14 +00:00
|
|
|
if (flags[5] & 0x10)
|
2014-02-28 04:09:57 +00:00
|
|
|
add_event(dc, sample->time.seconds, 0, 0, 0, QT_TRANSLATE_NOOP("gettextFromC", "Marker"));
|
2011-10-03 19:27:14 +00:00
|
|
|
if (flags[6] & 0x02)
|
2014-11-25 15:47:24 +00:00
|
|
|
add_event(dc, sample->time.seconds, 0, 0, 0, QT_TRANSLATE_NOOP("gettextFromC", "No tank data"));
|
2011-10-03 19:27:14 +00:00
|
|
|
if (flags[6] & 0x04)
|
2014-11-25 15:47:24 +00:00
|
|
|
add_event(dc, sample->time.seconds, 0, 0, 0, QT_TRANSLATE_NOOP("gettextFromC", "Low battery warning"));
|
2011-10-03 19:27:14 +00:00
|
|
|
if (flags[6] & 0x08)
|
2014-11-25 15:47:24 +00:00
|
|
|
add_event(dc, sample->time.seconds, 0, 0, 0, QT_TRANSLATE_NOOP("gettextFromC", "Low battery alert"));
|
2014-02-28 04:09:57 +00:00
|
|
|
/* flags[7] reflects the little on screen icons that remind of previous
|
2011-10-03 19:27:14 +00:00
|
|
|
* warnings / alerts - not useful for events */
|
2012-11-10 08:28:02 +00:00
|
|
|
|
2012-12-05 05:06:54 +00:00
|
|
|
#if UEMIS_DEBUG & 32
|
|
|
|
int i, j;
|
|
|
|
for (i = 0; i < 8; i++) {
|
|
|
|
printf(" %d: ", 29 + i);
|
|
|
|
for (j = 7; j >= 0; j--)
|
2014-02-28 04:09:57 +00:00
|
|
|
printf("%c", flags[i] & 1 << j ? '1' : '0');
|
2012-12-05 05:06:54 +00:00
|
|
|
}
|
|
|
|
printf("\n");
|
|
|
|
#endif
|
2012-11-29 04:13:21 +00:00
|
|
|
/* now add deco / NDL
|
2012-12-05 05:06:54 +00:00
|
|
|
* we don't use events but store this in the sample - that makes much more sense
|
|
|
|
* for the way we display this information
|
|
|
|
* What we know about the encoding so far:
|
|
|
|
* flags[3].bit0 | flags[5].bit1 != 0 ==> in deco
|
|
|
|
* flags[0].bit7 == 1 ==> Safety Stop
|
|
|
|
* otherwise NDL */
|
|
|
|
stopdepth = rel_mbar_to_depth(u_sample->hold_depth, dive);
|
|
|
|
if ((flags[3] & 1) | (flags[5] & 2)) {
|
|
|
|
/* deco */
|
2014-01-15 18:54:41 +00:00
|
|
|
sample->in_deco = true;
|
2012-12-05 05:06:54 +00:00
|
|
|
sample->stopdepth.mm = stopdepth;
|
2014-02-28 04:09:57 +00:00
|
|
|
sample->stoptime.seconds = u_sample->hold_time * 60;
|
2012-12-05 05:06:54 +00:00
|
|
|
sample->ndl.seconds = 0;
|
|
|
|
} else if (flags[0] & 128) {
|
|
|
|
/* safety stop - distinguished from deco stop by having
|
|
|
|
* both ndl and stop information */
|
2014-01-15 18:54:41 +00:00
|
|
|
sample->in_deco = false;
|
2012-12-05 05:06:54 +00:00
|
|
|
sample->stopdepth.mm = stopdepth;
|
2014-02-28 04:09:57 +00:00
|
|
|
sample->stoptime.seconds = u_sample->hold_time * 60;
|
2012-12-05 05:06:54 +00:00
|
|
|
sample->ndl.seconds = lastndl;
|
2012-11-29 04:13:21 +00:00
|
|
|
} else {
|
2012-12-05 05:06:54 +00:00
|
|
|
/* NDL */
|
2014-01-15 18:54:41 +00:00
|
|
|
sample->in_deco = false;
|
2014-02-28 04:09:57 +00:00
|
|
|
lastndl = sample->ndl.seconds = u_sample->hold_time * 60;
|
2012-12-05 05:06:54 +00:00
|
|
|
sample->stopdepth.mm = 0;
|
|
|
|
sample->stoptime.seconds = 0;
|
2012-11-10 08:28:02 +00:00
|
|
|
}
|
2012-12-05 05:06:54 +00:00
|
|
|
#if UEMIS_DEBUG & 32
|
|
|
|
printf("%dm:%ds: p_amb_tol:%d surface:%d holdtime:%d holddepth:%d/%d ---> stopdepth:%d stoptime:%d ndl:%d\n",
|
2024-05-27 15:09:48 +00:00
|
|
|
sample->time.seconds / 60, sample->time.seconds % 60, u_sample->p_amb_tol, dive->dcs[0].surface_pressure.mbar,
|
2014-02-28 04:09:57 +00:00
|
|
|
u_sample->hold_time, u_sample->hold_depth, stopdepth, sample->stopdepth.mm, sample->stoptime.seconds, sample->ndl.seconds);
|
2012-12-05 05:06:54 +00:00
|
|
|
#endif
|
2011-10-03 19:27:14 +00:00
|
|
|
}
|
|
|
|
|
2011-09-15 04:00:49 +00:00
|
|
|
/*
|
|
|
|
* parse uemis base64 data blob into struct dive
|
|
|
|
*/
|
2024-04-29 05:02:54 +00:00
|
|
|
void uemis::parse_divelog_binary(std::string_view base64, struct dive *dive)
|
2014-02-28 04:09:57 +00:00
|
|
|
{
|
2013-04-08 02:50:26 +00:00
|
|
|
struct sample *sample = NULL;
|
2024-04-23 14:09:52 +00:00
|
|
|
uemis_sample *u_sample;
|
2024-05-27 15:09:48 +00:00
|
|
|
struct divecomputer *dc = &dive->dcs[0];
|
2024-04-23 14:09:52 +00:00
|
|
|
int dive_template, gasoffset;
|
2015-04-22 06:31:03 +00:00
|
|
|
uint8_t active = 0;
|
2011-09-15 04:00:49 +00:00
|
|
|
|
2024-04-23 14:09:52 +00:00
|
|
|
auto data = convert_base64(base64);
|
2024-05-27 15:09:48 +00:00
|
|
|
dive->dcs[0].airtemp.mkelvin = C_to_mkelvin((*(uint16_t *)(data.data() + 45)) / 10.0);
|
|
|
|
dive->dcs[0].surface_pressure.mbar = *(uint16_t *)(data.data() + 43);
|
2024-04-23 14:09:52 +00:00
|
|
|
if (*(uint8_t *)(data.data() + 19))
|
2024-05-27 15:09:48 +00:00
|
|
|
dive->dcs[0].salinity = SEAWATER_SALINITY; /* avg grams per 10l sea water */
|
2012-11-12 20:17:52 +00:00
|
|
|
else
|
2024-05-27 15:09:48 +00:00
|
|
|
dive->dcs[0].salinity = FRESHWATER_SALINITY; /* grams per 10l fresh water */
|
2012-11-12 20:17:52 +00:00
|
|
|
|
2012-11-29 05:02:03 +00:00
|
|
|
/* this will allow us to find the last dive read so far from this computer */
|
2024-05-18 15:03:19 +00:00
|
|
|
dc->model = "Uemis Zurich";
|
2024-04-23 14:09:52 +00:00
|
|
|
dc->deviceid = *(uint32_t *)(data.data() + 9);
|
|
|
|
dc->diveid = *(uint16_t *)(data.data() + 7);
|
2012-11-29 00:11:19 +00:00
|
|
|
/* remember the weight units used in this dive - we may need this later when
|
|
|
|
* parsing the weight */
|
2024-04-23 14:09:52 +00:00
|
|
|
weight_unit(dc->diveid, *(uint8_t *)(data.data() + 24));
|
2011-09-30 05:12:42 +00:00
|
|
|
/* dive template in use:
|
|
|
|
0 = air
|
|
|
|
1 = nitrox (B)
|
|
|
|
2 = nitrox (B+D)
|
|
|
|
3 = nitrox (B+T+D)
|
|
|
|
uemis cylinder data is insane - it stores seven tank settings in a block
|
|
|
|
and the template tells us which of the four groups of tanks we need to look at
|
|
|
|
*/
|
2024-04-23 14:09:52 +00:00
|
|
|
gasoffset = dive_template = *(uint8_t *)(data.data() + 115);
|
|
|
|
if (dive_template == 3)
|
2011-09-30 05:12:42 +00:00
|
|
|
gasoffset = 4;
|
2024-04-23 14:09:52 +00:00
|
|
|
if (dive_template == 0)
|
|
|
|
dive_template = 1;
|
|
|
|
for (int i = 0; i < dive_template; i++) {
|
|
|
|
float volume = *(float *)(data.data() + 116 + 25 * (gasoffset + i)) * 1000.0f;
|
2011-10-03 16:55:17 +00:00
|
|
|
/* uemis always assumes a working pressure of 202.6bar (!?!?) - I first thought
|
|
|
|
* it was 3000psi, but testing against all my dives gets me that strange number.
|
|
|
|
* Still, that's of course completely bogus and shows they don't get how
|
|
|
|
* cylinders are named in non-metric parts of the world...
|
|
|
|
* we store the incorrect working pressure to get the SAC calculations "close"
|
|
|
|
* but the user will have to correct this manually
|
|
|
|
*/
|
2019-08-04 16:44:57 +00:00
|
|
|
cylinder_t *cyl = get_or_create_cylinder(dive, i);
|
|
|
|
cyl->type.size.mliter = lrintf(volume);
|
|
|
|
cyl->type.workingpressure.mbar = 202600;
|
2024-04-23 14:09:52 +00:00
|
|
|
cyl->gasmix.o2.permille = *(uint8_t *)(data.data() + 120 + 25 * (gasoffset + i)) * 10;
|
2019-08-04 16:44:57 +00:00
|
|
|
cyl->gasmix.he.permille = 0;
|
2011-09-30 05:12:42 +00:00
|
|
|
}
|
2011-09-15 04:00:49 +00:00
|
|
|
/* first byte of divelog data is at offset 0x123 */
|
2024-04-23 14:09:52 +00:00
|
|
|
size_t i = 0x123;
|
|
|
|
u_sample = (uemis_sample *)(data.data() + i);
|
|
|
|
while ((i <= data.size()) && (data[i] != 0 || data[i + 1] != 0)) {
|
First step in cleaning up cylinder pressure sensor logic
This clarifies/changes the meaning of our "cylinderindex" entry in our
samples. It has been rather confused, because different dive computers
have done things differently, and the naming really hasn't helped.
There are two totally different - and independent - cylinder "indexes":
- the pressure sensor index, which indicates which cylinder the sensor
data is from.
- the "active cylinder" index, which indicates which cylinder we actually
breathe from.
These two values really are totally independent, and have nothing
what-so-ever to do with each other. The sensor index may well be fixed:
many dive computers only support a single pressure sensor (whether
wireless or wired), and the sensor index is thus always zero.
Other dive computers may support multiple pressure sensors, and the gas
switch event may - or may not - indicate that the sensor changed too. A
dive computer might give the sensor data for *all* cylinders it can read,
regardless of which one is the one we're actively breathing. In fact, some
dive computers might give sensor data for not just *your* cylinder, but
your buddies.
This patch renames "cylinderindex" in the samples as "sensor", making it
quite clear that it's about which sensor index the pressure data in the
sample is about.
The way we figure out which is the currently active gas is with an
explicit has change event. If a computer (like the Uemis Zurich) joins the
two concepts together, then a sensor change should also create a gas
switch event. This patch also changes the Uemis importer to do that.
Finally, it should be noted that the plot info works totally separately
from the sample data, and is about what we actually *display*, not about
the sample pressures etc. In the plot info, the "cylinderindex" does in
fact mean the currently active cylinder, and while it is initially set to
match the sensor information from the samples, we then walk the gas change
events and fix it up - and if the active cylinder differs from the sensor
cylinder, we clear the sensor data.
[Dirk Hohndel: this conflicted with some of my recent changes - I think
I merged things correctly...]
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-31 04:00:51 +00:00
|
|
|
if (u_sample->active_tank != active) {
|
2024-05-28 19:31:11 +00:00
|
|
|
if (u_sample->active_tank >= static_cast<int>(dive->cylinders.size())) {
|
2024-03-24 20:03:08 +00:00
|
|
|
report_info("got invalid sensor #%d was #%d", u_sample->active_tank, active);
|
2015-04-22 06:31:03 +00:00
|
|
|
} else {
|
|
|
|
active = u_sample->active_tank;
|
|
|
|
add_gas_switch_event(dive, dc, u_sample->dive_time, active);
|
|
|
|
}
|
First step in cleaning up cylinder pressure sensor logic
This clarifies/changes the meaning of our "cylinderindex" entry in our
samples. It has been rather confused, because different dive computers
have done things differently, and the naming really hasn't helped.
There are two totally different - and independent - cylinder "indexes":
- the pressure sensor index, which indicates which cylinder the sensor
data is from.
- the "active cylinder" index, which indicates which cylinder we actually
breathe from.
These two values really are totally independent, and have nothing
what-so-ever to do with each other. The sensor index may well be fixed:
many dive computers only support a single pressure sensor (whether
wireless or wired), and the sensor index is thus always zero.
Other dive computers may support multiple pressure sensors, and the gas
switch event may - or may not - indicate that the sensor changed too. A
dive computer might give the sensor data for *all* cylinders it can read,
regardless of which one is the one we're actively breathing. In fact, some
dive computers might give sensor data for not just *your* cylinder, but
your buddies.
This patch renames "cylinderindex" in the samples as "sensor", making it
quite clear that it's about which sensor index the pressure data in the
sample is about.
The way we figure out which is the currently active gas is with an
explicit has change event. If a computer (like the Uemis Zurich) joins the
two concepts together, then a sensor change should also create a gas
switch event. This patch also changes the Uemis importer to do that.
Finally, it should be noted that the plot info works totally separately
from the sample data, and is about what we actually *display*, not about
the sample pressures etc. In the plot info, the "cylinderindex" does in
fact mean the currently active cylinder, and while it is initially set to
match the sensor information from the samples, we then walk the gas change
events and fix it up - and if the active cylinder differs from the sensor
cylinder, we clear the sensor data.
[Dirk Hohndel: this conflicted with some of my recent changes - I think
I merged things correctly...]
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-12-31 04:00:51 +00:00
|
|
|
}
|
2012-11-24 02:51:27 +00:00
|
|
|
sample = prepare_sample(dc);
|
2011-10-03 19:27:14 +00:00
|
|
|
sample->time.seconds = u_sample->dive_time;
|
2012-11-12 20:17:52 +00:00
|
|
|
sample->depth.mm = rel_mbar_to_depth(u_sample->water_pressure, dive);
|
2014-01-04 00:00:28 +00:00
|
|
|
sample->temperature.mkelvin = C_to_mkelvin(u_sample->dive_temperature / 10.0);
|
2022-03-06 10:34:12 +00:00
|
|
|
add_sample_pressure(sample, active, (u_sample->tank_pressure_high * 256 + u_sample->tank_pressure_low) * 10);
|
2012-12-08 04:08:29 +00:00
|
|
|
sample->cns = u_sample->cns;
|
2024-04-23 14:09:52 +00:00
|
|
|
event(dive, dc, sample, u_sample);
|
2011-09-15 04:00:49 +00:00
|
|
|
i += 0x25;
|
2011-10-03 19:27:14 +00:00
|
|
|
u_sample++;
|
2011-09-15 04:00:49 +00:00
|
|
|
}
|
2013-04-08 02:50:26 +00:00
|
|
|
if (sample)
|
2024-05-27 15:09:48 +00:00
|
|
|
dive->dcs[0].duration.seconds = sample->time.seconds - 1;
|
2014-11-07 20:50:31 +00:00
|
|
|
|
|
|
|
/* get data from the footer */
|
2024-05-18 19:04:58 +00:00
|
|
|
add_extra_data(dc, "FW Version",
|
|
|
|
format_string_std("%1u.%02u", data[18], data[17]));
|
|
|
|
add_extra_data(dc, "Serial",
|
|
|
|
format_string_std("%08x", *(uint32_t *)(data.data() + 9)));
|
|
|
|
add_extra_data(dc, "main battery after dive",
|
|
|
|
std::to_string(*(uint16_t *)(data.data() + i + 35)));
|
|
|
|
add_extra_data(dc, "no fly time",
|
|
|
|
format_string_std("%0u:%02u", FRACTION_TUPLE(*(uint16_t *)(data.data() + i + 24), 60)));
|
|
|
|
add_extra_data(dc, "no dive time",
|
|
|
|
format_string_std("%0u:%02u", FRACTION_TUPLE(*(uint16_t *)(data.data() + i + 26), 60)));
|
|
|
|
add_extra_data(dc, "desat time",
|
|
|
|
format_string_std("%0u:%02u", FRACTION_TUPLE(*(uint16_t *)(data.data() + i + 28), 60)));
|
|
|
|
add_extra_data(dc, "allowed altitude",
|
|
|
|
std::to_string(*(uint16_t *)(data.data() + i + 30)));
|
2014-11-07 20:50:31 +00:00
|
|
|
|
2011-09-15 04:00:49 +00:00
|
|
|
return;
|
|
|
|
}
|