--- src/cochran_emc_parser.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/cochran_emc_parser.c b/src/cochran_emc_parser.c index 635f050..5d430f4 100644 --- a/src/cochran_emc_parser.c +++ b/src/cochran_emc_parser.c @@ -246,7 +246,7 @@ cochran_emc_parser_samples_foreach (dc_parser_t *abstract, // Ascent rate is logged in the 0th sample, temp in the 1st, repeat. if (time % 2 == 0) { // Ascent rate - ascent_rate = (s[1] & 0x7f) / 4 * (s[1] & 0x80 ? 1 : -1); + ascent_rate = (float) (s[1] & 0x7f) / 4 * (s[1] & 0x80 ? 1 : -1); sample.ascent_rate = ascent_rate * FEET; if (callback) callback (DC_SAMPLE_ASCENT_RATE, sample, userdata); } else {
--- src/cochran_commander.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-)
diff --git a/src/cochran_commander.c b/src/cochran_commander.c index 3ba3786..8bb61c9 100644 --- a/src/cochran_commander.c +++ b/src/cochran_commander.c @@ -22,6 +22,7 @@ #include <string.h> // memcpy, memcmp #include <stdlib.h> // malloc, free #include <assert.h> // assert +#include <stdio.h> // DEBUG JVO
#include <libdivecomputer/cochran.h>
@@ -632,7 +633,7 @@ cochran_get_sample_parms(dc_device_t *abstract) pre_dive_offset = array_uint32_le (&(d->logbook[i * layout->rb_log_size + layout->pt_log_profile_pre])); end_dive_offset = array_uint32_le (&(d->logbook[i * layout->rb_log_size - + layout->pt_log_profile_begin])); + + layout->pt_log_profile_end]));
// Check for ring buffer wrap-around. if (pre_dive_offset > end_dive_offset) @@ -678,7 +679,7 @@ cochran_read_samples(dc_device_t *abstract, dc_event_progress_t *progress) free(d->sample);
d->sample = (unsigned char *) malloc(d->sample_size); - if (device == NULL) { + if (d->sample == NULL) { ERROR (abstract->context, "Failed to allocate memory."); return DC_STATUS_NOMEMORY; } @@ -864,7 +865,7 @@ cochran_commander_device_foreach (dc_device_t *abstract, dc_status_t rc;
unsigned char *log, *fingerprint, *sample, *dive; - int sample_size, dive_size; + unsigned int sample_size, dive_size;
rc = cochran_commander_device_read_all (abstract);
@@ -896,27 +897,27 @@ cochran_commander_device_foreach (dc_device_t *abstract,
// Build dive blob dive_size = COCHRAN_MODEL_SIZE + layout->rb_log_size + sample_size; - dive = malloc(dive_size); + dive = (unsigned char *) malloc(dive_size); if (dive == NULL) return DC_STATUS_NOMEMORY;
memcpy(dive, data->id + 0x3B, 8); // model string - memcpy(dive + COCHRAN_MODEL_SIZE, log, layout->rb_log_size); + memcpy(dive + COCHRAN_MODEL_SIZE, log, layout->rb_log_size); // log
+ // Copy profile data if (sample_start_address <= sample_end_address) { memcpy(dive + COCHRAN_MODEL_SIZE + layout->rb_log_size, sample, sample_size); } else { // It wrapped the buffer, copy two sections - unsigned int size = layout->rb_profile_end - - sample_start_address; + unsigned int size = layout->rb_profile_end - sample_start_address; memcpy(dive + COCHRAN_MODEL_SIZE + layout->rb_log_size, sample, size); memcpy(dive + COCHRAN_MODEL_SIZE + layout->rb_log_size + size, data->sample, sample_size - size); }
- if (callback && !callback ((unsigned char *) dive, dive_size, - fingerprint, COCHRAN_FINGERPRINT_SIZE, userdata)) { + if (callback && !callback (dive, dive_size, fingerprint, + COCHRAN_FINGERPRINT_SIZE, userdata)) { free(dive); return DC_STATUS_SUCCESS; }
--- src/cochran_commander.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/src/cochran_commander.c b/src/cochran_commander.c index 8bb61c9..9328aaa 100644 --- a/src/cochran_commander.c +++ b/src/cochran_commander.c @@ -74,7 +74,7 @@ static cochran_layout_t cochran_layout_emc20 = { ENDIAN_LE, /* endian */ DATE_SMHDMY, /* date_format */ ADDRESS_32_BIT, /* address_size */ - 825600, /* high_baud_rate */ + 806400, /* high_baud_rate was 825600 */
0x00000000, /* rb_logbook_begin */ 0x00080000, /* rb_logbook_end */ @@ -97,7 +97,7 @@ static cochran_layout_t cochran_layout_emc16 = { ENDIAN_LE, /* endian */ DATE_SMHDMY, /* date_format */ ADDRESS_32_BIT, /* address_size */ - 825600, /* high_baud_rate */ + 806400, /* high_baud_rate */
0x00000000, /* rb_logbook_begin */ 0x00080000, /* rb_logbook_end */ @@ -120,7 +120,7 @@ static cochran_layout_t cochran_layout_emc14 = { ENDIAN_LE, /* endian */ DATE_SMHDMY, /* date_format */ ADDRESS_32_BIT, /* address_size */ - 825600, /* high_baud_rate */ + 806400, /* high_baud_rate */
0x00000000, /* rb_logbook_begin */ 0x00020000, /* rb_logbook_end */ @@ -183,7 +183,7 @@ cochran_packet (cochran_device_t *device, dc_event_progress_t *progress, if (high_speed) { serial_sleep(device->port, 45);
- // Rates are odd, like 825600 for the EMC, 115200 for commander + // Rates are odd, like 806400 for the EMC, 115200 for commander cochran_layout_t *layout = cochran_commander_get_layout(device->model_string); rc = serial_configure(device->port, layout->high_baud_rate, 8, SERIAL_PARITY_NONE, 2, SERIAL_FLOWCONTROL_NONE);
--- examples/Makefile.am | 5 +- examples/cochran_download.c | 372 -------------------------------------------- 2 files changed, 1 insertion(+), 376 deletions(-) delete mode 100644 examples/cochran_download.c
diff --git a/examples/Makefile.am b/examples/Makefile.am index aaa7e4f..12bca6f 100644 --- a/examples/Makefile.am +++ b/examples/Makefile.am @@ -3,8 +3,7 @@ LDADD = $(top_builddir)/src/libdivecomputer.la AM_LDFLAGS = -lm
bin_PROGRAMS = \ - dctool \ - cochran_download + dctool
dctool_SOURCES = \ common.h \ @@ -21,5 +20,3 @@ dctool_SOURCES = \ dctool_fwupdate.c \ utils.h \ utils.c - -cochran_download_SOURCES = cochran_download.c diff --git a/examples/cochran_download.c b/examples/cochran_download.c deleted file mode 100644 index 01df25d..0000000 --- a/examples/cochran_download.c +++ /dev/null @@ -1,372 +0,0 @@ -/* - * cochran_download - * - * Copyright (C) 2014 John Van Ostrand - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA - */ - -#include <stdio.h> // fopen, fwrite, fclose -#include <stdlib.h> -#include <string.h> -#include <signal.h> -#include <unistd.h> -#include <sys/stat.h> -#include <sys/types.h> -#include <fcntl.h> - - -#include <libdivecomputer/context.h> -#include <libdivecomputer/device.h> -#include <libdivecomputer/parser.h> -#include <libdivecomputer/cochran.h> - - -volatile sig_atomic_t g_cancel = 0; - -void -sighandler (int signum) -{ - // Restore the default signal handler. - signal (signum, SIG_DFL); - - g_cancel = 1; -} - -static int -cancel_cb (void *userdata) -{ - return g_cancel; -} - -static void -usage (const char *filename) -{ - fprintf (stderr, "Usage:\n\n"); - fprintf (stderr, " %s [options] devname\n\n", filename); - fprintf (stderr, "Options:\n\n"); - fprintf (stderr, " -d dirname Dump data to dirname.\n"); - fprintf (stderr, " -f Force dump despite download errors\n"); - fprintf (stderr, " -h Show this help message.\n\n"); - fprintf (stderr, "\n\n"); -} - -static dc_status_t -search (dc_descriptor_t **out, const char *name, dc_family_t backend, unsigned int model) -{ - dc_status_t rc = DC_STATUS_SUCCESS; - - dc_iterator_t *iterator = NULL; - rc = dc_descriptor_iterator (&iterator); - if (rc != DC_STATUS_SUCCESS) { - printf ("Error creating the device descriptor iterator.\n"); - return rc; - } - - dc_descriptor_t *descriptor = NULL, *current = NULL; - while ((rc = dc_iterator_next (iterator, &descriptor)) == DC_STATUS_SUCCESS) - { - if (backend == dc_descriptor_get_type (descriptor)) { - dc_descriptor_free (current); - current = descriptor; - break; - } - - dc_descriptor_free (descriptor); - } - - if (rc != DC_STATUS_SUCCESS && rc != DC_STATUS_DONE) { - dc_descriptor_free (current); - dc_iterator_free (iterator); - printf ("Error iterating the device descriptors.\n"); - return rc; - } - - dc_iterator_free (iterator); - - *out = current; - - return DC_STATUS_SUCCESS; -} - -static dc_status_t -write_dump(const char *dump, unsigned int size, const char *fname) -{ - int fd, written; - - if (size > 0) { - fd = open(fname, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH ); - if (fd == -1) { - printf("Unable to open %s for writing\n", fname); - exit; - } - written = write(fd, dump, size); - if (written != size) { - printf("Error writing %s. Wrote %d expected %d.\n", fname, written, size); - return (DC_STATUS_UNSUPPORTED); - } - } - return (DC_STATUS_SUCCESS); -} - -#define hexchar(n) ("0123456789abcdef"[(n) & 15]) - -static int show_line(unsigned offset, const unsigned char *data, - unsigned size, int show_empty) -{ - unsigned char bits; - int i, off; - char buffer[120]; - - if (size > 16) - size = 16; - - bits = 0; - memset(buffer, ' ', sizeof(buffer)); - off = sprintf(buffer, "%06x ", offset); - for (i = 0; i < size; i++) { - char *hex = buffer + off + 3 * i; - char *asc = buffer + off + 50 + i; - unsigned char byte = data[i]; - - hex[0] = hexchar(byte >> 4); - hex[1] = hexchar(byte); - bits |= byte; - if (byte < 32 || byte > 126) - byte = '.'; - asc[0] = byte; - asc[1] = 0; - } - - if (bits) { - puts(buffer); - return 1; - } - if (show_empty) - puts("..."); - return 0; -} - -static void cochran_debug_write(const unsigned char *data, unsigned size) -{ - return; - - int show = 1, i; - - - for (i = 0; i < size; i += 16) - show = show_line(i, data + i, size - i, show); -} - - -#define array_uint32_le(p) ( (unsigned char) (p)[0] + ((unsigned char) (p)[1] << 8) \ - + ((unsigned char) (p)[2] << 16) + ((unsigned char) (p)[3] << 24) ) - -static dc_status_t -dowork (dc_context_t *context, dc_descriptor_t *descriptor, const char *devname, const char *dirname, unsigned int force_flag) -{ - dc_status_t rc = DC_STATUS_SUCCESS; - - struct stat dstat; - - // Open the device. - dc_device_t *device = NULL; - rc = dc_device_open (&device, context, descriptor, devname); - if (rc != DC_STATUS_SUCCESS) { - printf ("Error opening %s.\n", devname); - return rc; - } - - // Register the cancellation handler. - rc = dc_device_set_cancel (device, cancel_cb, NULL); - if (rc != DC_STATUS_SUCCESS) { - printf ("Error registering the cancellation handler.\n"); - dc_device_close (device); - return rc; - } - - // Create directory if needed - int src; - src = stat(dirname, &dstat); - - if ( src == -1 ) { - if (mkdir(dirname, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH)) { - printf("Unable to create directory\n"); - exit; - } - } - - // TODO Run dump and write files - dc_buffer_t *dump = dc_buffer_new(0); - - rc = dc_device_dump (device, dump); - - cochran_debug_write(dc_buffer_get_data(dump), dc_buffer_get_size(dump)); - exit; - - if (rc == DC_STATUS_SUCCESS || force_flag) { - char fname[128]; - char *d = dc_buffer_get_data(dump); - unsigned int ptr = 0, start, size; - - sprintf(fname, "%s/info-x05x9dxffx00x43x00.bin", dirname); - start = array_uint32_le(d + ptr); - size = array_uint32_le(d + ptr + 5) - start; -printf("%s, start = %d, size = %d\n", fname, start, size); - write_dump(d + start, size, fname); - - ptr += 5; - start = array_uint32_le(d + ptr); - size = array_uint32_le(d + ptr + 5) - start; - if (*(d + ptr - 1) == 1) - sprintf(fname, "%s/info-xdbx7fxffx00x43x00.bin", dirname); - else - sprintf(fname, "%s/info-x05x9dxffx00x43x00.bin", dirname); - write_dump(d + start, size, fname); - - ptr += 5; - start = array_uint32_le(d + ptr); - size = array_uint32_le(d + ptr + 5) - start; - sprintf(fname, "%s/config-x96x00.bin", dirname); -printf("%s, start = %d, size = %d\n", fname, start, size); - write_dump(d + start, size, fname); - - ptr += 5; - start = array_uint32_le(d + ptr); - size = array_uint32_le(d + ptr + 5) - start; - sprintf(fname, "%s/config-x96x01.bin", dirname); -printf("%s, start = %d, size = %d\n", fname, start, size); - write_dump(d + start, size, fname); - - ptr += 5; - start = array_uint32_le(d + ptr); - size = array_uint32_le(d + ptr + 5) - start; - sprintf(fname, "%s/config-x96x02.bin", dirname); -printf("%s, start = %d, size = %d\n", fname, start, size); - write_dump(d + start, size, fname); - - ptr += 5; - start = array_uint32_le(d + ptr); - size = array_uint32_le(d + ptr + 5) - start; - sprintf(fname, "%s/config-x96x03.bin", dirname); -printf("%s, start = %d, size = %d\n", fname, start, size); - write_dump(d + start, size, fname); - - ptr += 5; - start = array_uint32_le(d + ptr); - size = array_uint32_le(d + ptr + 5) - start; - sprintf(fname, "%s/misc-x89x05x00x00x00xdcx05.bin", dirname); -printf("%s, start = %d, size = %d\n", fname, start, size); - write_dump(d + start, size, fname); - - ptr += 5; - start = array_uint32_le(d + ptr); - size = array_uint32_le(d + ptr + 5) - start; - sprintf(fname, "%s/logbook.bin", dirname); -printf("%s, start = %d, size = %d\n", fname, start, size); - write_dump(d + start, size, fname); - - ptr += 5; - start = array_uint32_le(d + ptr); - size = array_uint32_le(d + ptr + 5) - start; - sprintf(fname, "%s/sample.bin", dirname); -printf("%s, start = %d, size = %d\n", fname, start, size); - write_dump(d + start, size, fname); - - dc_buffer_free (dump); - } else { - printf("Dive computer read failure\n"); - } - - // Close the device. - rc = dc_device_close (device); - if (rc != DC_STATUS_SUCCESS) { - printf ("Error closing the device.\n"); - return rc; - } - - return DC_STATUS_SUCCESS; -} - - -int -main (int argc, char *argv[]) -{ - extern char *optarg; - extern int optind, opterr, optopt; - - // Default values. - dc_family_t backend = DC_FAMILY_COCHRAN_COMMANDER; - - // Command line arguments - const char *devname = NULL, *dirname; - unsigned int force_flag = 0; - - - // Parse command-line options. - int opt = 0; - while ((opt = getopt (argc, argv, "d:ls:h")) != -1) { - switch (opt) { - case 'd': // dump data to directory - dirname = optarg; - break; - case 'f': // Force dump despite download error - force_flag = 1; - break; - case '?': - case 'h': - default: - usage (argv[0]); - return EXIT_FAILURE; - } - } - - if (optind < argc) - devname = argv[optind]; - - - signal (SIGINT, sighandler); - - dc_context_t *context = NULL; - dc_status_t rc = dc_context_new (&context); - if (rc != DC_STATUS_SUCCESS) { - return EXIT_FAILURE; - } - - dc_context_set_loglevel (context, DC_LOGLEVEL_NONE); - //dc_context_set_logfunc (context, logfunc, NULL); - - /* Search for a matching device descriptor. */ - dc_descriptor_t *descriptor = NULL; - rc = search (&descriptor, NULL, backend, 0); - if (rc != DC_STATUS_SUCCESS) { - return EXIT_FAILURE; - } - - /* Fail if no device descriptor found. */ - if (descriptor == NULL) { - printf ("No matching device found.\n"); - usage (argv[0]); - return EXIT_FAILURE; - } - - rc = dowork (context, descriptor, devname, dirname, force_flag); - - dc_descriptor_free (descriptor); - dc_context_free (context); - - return rc != DC_STATUS_SUCCESS ? EXIT_FAILURE : EXIT_SUCCESS; -}
--- src/cochran_cmdr_parser.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/cochran_cmdr_parser.c b/src/cochran_cmdr_parser.c index b2b9748..af0f112 100644 --- a/src/cochran_cmdr_parser.c +++ b/src/cochran_cmdr_parser.c @@ -170,7 +170,7 @@ cochran_cmdr_parser_samples_foreach (dc_parser_t *abstract, // Ascent rate is logged in the 0th sample, temp in the 1st, repeat. if (time % 2 == 0) { // Ascent rate - ascent_rate = (s[1] & 0x7f) / 4 * (s[1] & 0x80 ? 1 : -1); + ascent_rate = (float) (s[1] & 0x7f) / 4 * (s[1] & 0x80 ? 1 : -1); sample.ascent_rate = ascent_rate * FEET; if (callback) callback (DC_SAMPLE_ASCENT_RATE, sample, userdata); } else {
--- src/cochran_commander_parser.c | 9 +++++++++ src/cochran_commander_parser.h | 8 ++++---- src/cochran_emc_parser.c | 12 ++++++++++++ 3 files changed, 25 insertions(+), 4 deletions(-)
diff --git a/src/cochran_commander_parser.c b/src/cochran_commander_parser.c index bce3cad..da92995 100644 --- a/src/cochran_commander_parser.c +++ b/src/cochran_commander_parser.c @@ -208,6 +208,15 @@ cochran_commander_handle_event (dc_parser_t *abstract, // Indicates to raise ceiling by 10 ft (shallower) // Handled in calling function break; + case 0xC0: // Switched to FO2 21% mode (surface) + // Event seen upon surfacing + // handled in calling function + break; + case 0xCD: // Switched to deco blend + case 0xEF: // Switched to gas blend 2 + case 0xF3: // Switched to gas blend 1 + // handled in calling function + break; default: // Don't send known events of type NONE if (! event.type == SAMPLE_EVENT_NONE) { diff --git a/src/cochran_commander_parser.h b/src/cochran_commander_parser.h index 44340b5..06d5482 100644 --- a/src/cochran_commander_parser.h +++ b/src/cochran_commander_parser.h @@ -39,7 +39,7 @@ static cochran_events_t cochran_events[] = { { 0xBD, 1, "Switched to nomal PO2 setting", SAMPLE_EVENT_NONE, SAMPLE_FLAGS_NONE }, { 0xC0, 1, "Switched to FO2 21% mode", - SAMPLE_EVENT_GASCHANGE, SAMPLE_FLAGS_NONE }, + SAMPLE_EVENT_NONE, SAMPLE_FLAGS_NONE }, { 0xC1, 1, "Ascent rate greater than limit", SAMPLE_EVENT_ASCENT, SAMPLE_FLAGS_BEGIN }, { 0xC2, 1, "Low battery warning", @@ -57,7 +57,7 @@ static cochran_events_t cochran_events[] = { { 0xCE, 1, "Non-decompression warning", SAMPLE_EVENT_RBT, SAMPLE_FLAGS_BEGIN }, { 0xCD, 1, "Switched to deco blend", - SAMPLE_EVENT_NONE, SAMPLE_FLAGS_BEGIN }, + SAMPLE_EVENT_NONE, SAMPLE_FLAGS_NONE }, { 0xD0, 1, "Breathing rate alarm", SAMPLE_EVENT_NONE, SAMPLE_FLAGS_BEGIN }, { 0xD3, 1, "Low gas 1 flow rate", @@ -77,11 +77,11 @@ static cochran_events_t cochran_events[] = { { 0xEE, 1, "End non-decompresison warning", SAMPLE_EVENT_RBT, SAMPLE_FLAGS_END }, { 0xEF, 1, "Switch to blend 2", - SAMPLE_EVENT_GASCHANGE2, SAMPLE_FLAGS_NONE }, + SAMPLE_EVENT_NONE, SAMPLE_FLAGS_NONE }, { 0xF0, 1, "Breathing rate alarm", SAMPLE_EVENT_NONE, SAMPLE_FLAGS_END }, { 0xF3, 1, "Switch to blend 1", - SAMPLE_EVENT_GASCHANGE2, SAMPLE_FLAGS_NONE }, + SAMPLE_EVENT_NONE, SAMPLE_FLAGS_NONE }, { 0xF6, 1, "End Depth is less than ceiling", SAMPLE_EVENT_CEILING, SAMPLE_FLAGS_END }, { 0x00, 1, NULL, diff --git a/src/cochran_emc_parser.c b/src/cochran_emc_parser.c index 5d430f4..884f8aa 100644 --- a/src/cochran_emc_parser.c +++ b/src/cochran_emc_parser.c @@ -232,6 +232,18 @@ cochran_emc_parser_samples_foreach (dc_parser_t *abstract, sample.deco.time = (array_uint16_le(s + 3) + 1) * 60; if (callback) callback(DC_SAMPLE_DECO, sample, userdata); break; + case 0xC0: // Switched to FO2 21% mode (surface) + // Event seen upon surfacing + break; + case 0xCD: // Switched to deco blend + case 0xEF: // Switched to gas blend 2 + sample.gasmix = 1; + if (callback) callback(DC_SAMPLE_GASMIX, sample, userdata); + break; + case 0xF3: // Switched to gas blend 1 + sample.gasmix = 0; + if (callback) callback(DC_SAMPLE_GASMIX, sample, userdata); + break; }
continue;