Uemis support: hack around the need to reconnect the Uemis Zurich

When the file system of the Zurich gets full, the only way to continue to
download from it, is to disconnect and reconnect the dive computer (which
resets the FAT file system that it emulates to 'empty').

This solution is rather hacky and weird because it does a hard count down in a
busy loop, but given the narrow use case, this may be acceptable.

This also adds support for the UEMIS_DIVE_OFFSET environment variable that
allows the user to skip dives on the device.

[refactored by Dirk Hohndel]

Signed-off-by: Oliver Schwaneberg <oliver.schwaneberg@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Oliver Schwaneberg 2022-02-06 22:05:43 +01:00 committed by Dirk Hohndel
parent af0b061266
commit 04c5ab0e36
3 changed files with 37 additions and 1 deletions

View file

@ -1,3 +1,4 @@
- Uemis support: fix the ability disconnect/reconnect the Zurich when its filesystem is full
- libdivecomputer: add support for latest BLE hardware in OSTC dive computers - libdivecomputer: add support for latest BLE hardware in OSTC dive computers
--- ---

View file

@ -9076,6 +9076,9 @@ msgid ""
"reconnect it. You can now retry (or start a new download session) and the " "reconnect it. You can now retry (or start a new download session) and the "
"download will continue where it stopped previously. You may have to do this " "download will continue where it stopped previously. You may have to do this "
"more than once, depending on how many dives are stored on the dive computer." "more than once, depending on how many dives are stored on the dive computer."
"You may define a dive number offset by setting environment variable "
"UEMIS_DIVE_OFFSET (e.g. export UEMIS_DIVE_OFFSET=300), "
"if subsurface starts downloading dives that are already synced."
msgstr "" msgstr ""
#. type: Title === #. type: Title ===

View file

@ -32,6 +32,7 @@
#include "subsurface-time.h" #include "subsurface-time.h"
#include "core/subsurface-string.h" #include "core/subsurface-string.h"
#define ACTION_RECONNECT QT_TRANSLATE_NOOP("gettextFromC", "Disconnect/reconnect the SDA")
#define ERR_FS_ALMOST_FULL QT_TRANSLATE_NOOP("gettextFromC", "Uemis Zurich: the file system is almost full.\nDisconnect/reconnect the dive computer\nand click \'Retry\'") #define ERR_FS_ALMOST_FULL QT_TRANSLATE_NOOP("gettextFromC", "Uemis Zurich: the file system is almost full.\nDisconnect/reconnect the dive computer\nand click \'Retry\'")
#define ERR_FS_FULL QT_TRANSLATE_NOOP("gettextFromC", "Uemis Zurich: the file system is full.\nDisconnect/reconnect the dive computer\nand click Retry") #define ERR_FS_FULL QT_TRANSLATE_NOOP("gettextFromC", "Uemis Zurich: the file system is full.\nDisconnect/reconnect the dive computer\nand click Retry")
#define ERR_FS_SHORT_WRITE QT_TRANSLATE_NOOP("gettextFromC", "Short write to req.txt file.\nIs the Uemis Zurich plugged in correctly?") #define ERR_FS_SHORT_WRITE QT_TRANSLATE_NOOP("gettextFromC", "Short write to req.txt file.\nIs the Uemis Zurich plugged in correctly?")
@ -1331,8 +1332,15 @@ const char *do_uemis_import(device_data_t *data)
char *endptr; char *endptr;
bool success, once = true; bool success, once = true;
int match_dive_and_log = 0; int match_dive_and_log = 0;
int dive_offset = 0;
int uemis_mem_status = UEMIS_MEM_OK; int uemis_mem_status = UEMIS_MEM_OK;
// To speed up sync you can skip downloading old dives by defining UEMIS_DIVE_OFFSET
if (getenv("UEMIS_DIVE_OFFSET")) {
dive_offset = atoi(getenv("UEMIS_DIVE_OFFSET"));
printf("Uemis: Using dive # offset %d\n", dive_offset);
}
#if UEMIS_DEBUG #if UEMIS_DEBUG
home = getenv("HOME"); home = getenv("HOME");
user = getenv("LOGNAME"); user = getenv("LOGNAME");
@ -1367,6 +1375,8 @@ const char *do_uemis_import(device_data_t *data)
first = start = atoi(newmax); first = start = atoi(newmax);
dive_to_read = mindiveid < first ? first - mindiveid : first; dive_to_read = mindiveid < first ? first - mindiveid : first;
if (dive_offset > 0)
start += dive_offset;
for (;;) { for (;;) {
#if UEMIS_DEBUG & 2 #if UEMIS_DEBUG & 2
debug_round++; debug_round++;
@ -1434,7 +1444,29 @@ const char *do_uemis_import(device_data_t *data)
#if UEMIS_DEBUG & 4 #if UEMIS_DEBUG & 4
fprintf(debugfile, "d_u_i out of memory, bailing\n"); fprintf(debugfile, "d_u_i out of memory, bailing\n");
#endif #endif
break; (void)uemis_get_answer(mountpath, "terminateSync", 0, 3, &result);
const char *errormsg = translate("gettextFromC", ACTION_RECONNECT);
for (int wait=60; wait >=0; wait--){
uemis_info("%s %ds", errormsg, wait);
usleep(1000000);
}
// Resetting to original state
filenr = 0;
max_mem_used = -1;
uemis_mem_status = get_memory(data->download_table, UEMIS_CHECK_DETAILS);
if (!uemis_get_answer(mountpath, "getDeviceId", 0, 1, &result))
goto bail;
if (strcmp(deviceid, param_buff[0]) != 0) {
printf(stderr, "Uemis: Device id has changed after reconnect!\n");
goto bail;
}
param_buff[0] = strdup(deviceid);
if (!uemis_get_answer(mountpath, "initSession", 1, 6, &result))
goto bail;
uemis_info(translate("gettextFromC", "Start download"));
if (!uemis_get_answer(mountpath, "processSync", 0, 2, &result))
goto bail;
param_buff[1] = "notempty";
} }
/* if the user clicked cancel, exit gracefully */ /* if the user clicked cancel, exit gracefully */
if (import_thread_cancelled) { if (import_thread_cancelled) {