diff options
author | John Van Ostrand <john@vanostrand.com> | 2017-05-26 19:58:06 -0400 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2017-05-27 07:22:14 -0700 |
commit | f604089ae3613c649fec9c01e7640280cd737e29 (patch) | |
tree | e0dcb4b944cbb95fc2d9dfb95a6af58301acff96 | |
parent | c6bc88b50d3d4c2bc4d0949ada7300aad9641c6e (diff) | |
download | subsurface-f604089ae3613c649fec9c01e7640280cd737e29.tar.gz |
Added support for older Cochran models that have configurable sample intervals.
Corrected problem where dive profiles would include post dive
surface interval samples.
Added detection for corrupt dives.
Signed-off-by: John Van Ostrand <john@vanostrand.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r-- | core/cochran.c | 65 | ||||
-rw-r--r-- | core/cochran.h | 4 |
2 files changed, 36 insertions, 33 deletions
diff --git a/core/cochran.c b/core/cochran.c index fdfb7bf1c..2e2dde32c 100644 --- a/core/cochran.c +++ b/core/cochran.c @@ -258,14 +258,10 @@ static void cochran_parse_header(const unsigned char *decode, unsigned mod, static int cochran_predive_event_bytes(unsigned char code) { int x = 0; - int gem_event_bytes[15][2] = {{0x00, 10}, {0x02, 17}, {0x08, 18}, - {0x09, 18}, {0x0c, 18}, {0x0d, 18}, - {0x0e, 18}, - {-1, 0}}; int cmdr_event_bytes[15][2] = {{0x00, 16}, {0x01, 20}, {0x02, 17}, {0x03, 16}, {0x06, 18}, {0x07, 18}, {0x08, 18}, {0x09, 18}, {0x0a, 18}, - {0x0b, 20}, {0x0c, 18}, {0x0d, 18}, + {0x0b, 18}, {0x0c, 18}, {0x0d, 18}, {0x0e, 18}, {0x10, 20}, {-1, 0}}; int emc_event_bytes[15][2] = {{0x00, 18}, {0x01, 22}, {0x02, 19}, @@ -276,10 +272,6 @@ static int cochran_predive_event_bytes(unsigned char code) switch (config.type) { case TYPE_GEMINI: - while (gem_event_bytes[x][0] != code && gem_event_bytes[x][0] != -1) - x++; - return gem_event_bytes[x][1]; - break; case TYPE_COMMANDER: while (cmdr_event_bytes[x][0] != code && cmdr_event_bytes[x][0] != -1) x++; @@ -479,22 +471,20 @@ static void cochran_parse_samples(struct dive *dive, const unsigned char *log, // Skip past pre-dive events unsigned int x = 0; - if (samples[x] != 0x40) { - unsigned int c; - while ((samples[x] & 0x80) == 0 && samples[x] != 0x40 && x < size) { - c = cochran_predive_event_bytes(samples[x]) + 1; -#ifdef COCHRAN_DEBUG - printf("Predive event: ", samples[x]); - for (int y = 0; y < c; y++) printf("%02x ", samples[x + y]); - putchar('\n'); -#endif + unsigned int c; + while (x < size && (samples[x] & 0x80) == 0 && samples[x] != 0x40) { + c = cochran_predive_event_bytes(samples[x]) + 1; +//#ifdef COCHRAN_DEBUG + printf("Predive event: ", samples[x]); + for (int y = 0; y < c && x + y < size; y++) printf("%02x ", samples[x + y]); + putchar('\n'); +//#endif x += c; - } } // Now process samples offset = x; - while (offset < size) { + while (offset + config.sample_size < size) { s = samples + offset; // Start with an empty sample @@ -556,21 +546,25 @@ static void cochran_parse_samples(struct dive *dive, const unsigned char *log, // Get NDL and deco information switch (seconds % 24) { case 20: - if (in_deco) { - // Fist stop time - //first_deco_time = (s[2] + s[5] * 256 + 1) * 60; // seconds - ndl = 0; - } else { - // NDL - ndl = (s[2] + s[5] * 256 + 1) * 60; // seconds - deco_time = 0; + if (offset + 5 < size) { + if (in_deco) { + // Fist stop time + //first_deco_time = (s[2] + s[5] * 256 + 1) * 60; // seconds + ndl = 0; + } else { + // NDL + ndl = (s[2] + s[5] * 256 + 1) * 60; // seconds + deco_time = 0; + } } break; case 22: - if (in_deco) { - // Total stop time - deco_time = (s[2] + s[5] * 256 + 1) * 60; // seconds - ndl = 0; + if (offset + 5 < size) { + if (in_deco) { + // Total stop time + deco_time = (s[2] + s[5] * 256 + 1) * 60; // seconds + ndl = 0; + } } break; } @@ -634,6 +628,13 @@ static void cochran_parse_dive(const unsigned char *decode, unsigned mod, * scrambled, but there seems to be size differences in the data, * so this just descrambles part of it: */ + + if (size < 0x4914 + config.logbook_size) { + // Analyst calls this a "Corrupt Beginning Summary" + free(buf); + return; + } + // Decode log entry (512 bytes + random prefix) partial_decode(0x48ff, 0x4914 + config.logbook_size, decode, 0, mod, in, size, buf); diff --git a/core/cochran.h b/core/cochran.h index 97d4361c8..58693be7a 100644 --- a/core/cochran.h +++ b/core/cochran.h @@ -5,8 +5,9 @@ #define CMD_DAY 2 #define CMD_MON 5 #define CMD_YEAR 4 -#define CME_START_OFFSET 6 // 4 bytes +#define CMD_START_OFFSET 6 // 4 bytes #define CMD_WATER_CONDUCTIVITY 25 // 1 byte, 0=low, 2=high +#define CMD_PREDIVE_OFFSET 30 #define CMD_START_SGC 42 // 2 bytes #define CMD_START_TEMP 45 // 1 byte, F #define CMD_START_DEPTH 56 // 2 bytes, /4=ft @@ -30,6 +31,7 @@ #define EMC_YEAR 5 #define EMC_START_OFFSET 6 // 4 bytes #define EMC_WATER_CONDUCTIVITY 24 // 1 byte bits 0:1, 0=low, 2=high +#define EMC_PREDIVE_OFFSET 30 #define EMC_START_DEPTH 42 // 2 byte, /256=ft #define EMC_START_TEMP 55 // 1 byte, F #define EMC_SIT 84 // 2 bytes, minutes, LE |