Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions src/suunto_nautic.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,10 @@
// size = compressed /Data + /Summary data bytes, exactly.
#define ENTRY_SIZE_OFFSET 16

// Safety cap on paginated-fetch pages (a Summary is a handful of pages, and
// /Logbook/Entries one page per ~18 dives).
#define MAX_PAGES 64
// Safety cap on paginated-fetch pages (a Summary is a handful of pages,
// /Logbook/Entries one page per ~18 dives, and a dive's Descriptors schema
// about 97).
#define MAX_PAGES 512

// The Suunto "MDS" chunk header wrapping each compressed block: 28 bytes,
// with the true payload size as a u16 LE at offset 20 and the compressed
Expand Down Expand Up @@ -718,8 +719,16 @@ suunto_nautic_device_stream_fetch (dc_device_t *abstract, const char *path, dc_b
goto release;
}

// A long dive streams for minutes, so a cancel is honoured between frames;
// the stream is still stopped below so the watch doesn't keep sending it.
unsigned int cancelled = 0;
unsigned int nframes = 0;
for (nframes = 0; nframes < MAX_CHUNKS; nframes++) {
if (device_is_cancelled (abstract)) {
cancelled = 1;
break;
}

unsigned char packet[MAX_PACKET] = {0};
size_t len = 0;
status = dc_iostream_read (device->iostream, packet, sizeof (packet), &len);
Expand Down Expand Up @@ -753,7 +762,7 @@ suunto_nautic_device_stream_fetch (dc_device_t *abstract, const char *path, dc_b
return status;
}
}
status = DC_STATUS_SUCCESS;
status = cancelled ? DC_STATUS_CANCELLED : DC_STATUS_SUCCESS;

if (nframes >= MAX_CHUNKS)
WARNING (abstract->context, "Stream for %s hit the %u-frame guard; the dive may be truncated.", path, MAX_CHUNKS);
Expand Down
11 changes: 8 additions & 3 deletions src/suunto_nautic_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -979,8 +979,8 @@ suunto_nautic_parser_parse (dc_parser_t *abstract, dc_sample_callback_t callback
// it). Trusted only on a record whose dive time agrees with the
// profile's, and when it is close to the sampled maximum. The same
// record's average depth and water temperature range are the app's
// figures too; the temperatures are taken only as a sane pair, since
// one Ocean dive records its minimum above its maximum.
// figures too. The Ocean can store the temperature pair reversed (the
// app then shows Min 29.35 and Max 18.85 C), so it is ordered here.
const unsigned char *record = suunto_nautic_summary_dive_record (sbem, sbem_size);
if (record && parser->divetime > 0) {
double divetime = array_float_le (record + SUMMARY_DIVE_DIVETIME);
Expand All @@ -996,7 +996,12 @@ suunto_nautic_parser_parse (dc_parser_t *abstract, dc_sample_callback_t callback
parser->avgdepth = avgdepth;
double tmin = array_float_le (record + SUMMARY_DIVE_TEMP_MIN);
double tmax = array_float_le (record + SUMMARY_DIVE_TEMP_MAX);
if (have_temperature && tmin > 250.0 && tmax < 330.0 && tmin <= tmax) {
if (tmin > tmax) {
double t = tmin;
tmin = tmax;
tmax = t;
}
if (have_temperature && tmin > 250.0 && tmax < 330.0) {
parser->temperature_minimum = tmin - 273.15;
parser->temperature_maximum = tmax - 273.15;
}
Expand Down
Loading