diff options
author | Dirk Hohndel <dirk@hohndel.org> | 2017-05-29 20:56:42 -0700 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2017-05-29 21:55:49 -0700 |
commit | cbe03fd88d8c065d12a1825eef7119252037c150 (patch) | |
tree | c7f35cda825a42786384b7380e35669ea1cbaec7 | |
parent | c05fe9fc9b1c76bb447af8033f9917b1f5d10a1c (diff) | |
download | subsurface-cbe03fd88d8c065d12a1825eef7119252037c150.tar.gz |
FTDI support: add minimal debugging output
Copied the libdivecomputer macros for convenience.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r-- | core/libdivecomputer.c | 15 | ||||
-rw-r--r-- | core/serial_ftdi.c | 6 |
2 files changed, 19 insertions, 2 deletions
diff --git a/core/libdivecomputer.c b/core/libdivecomputer.c index db4a7a434..d6492d162 100644 --- a/core/libdivecomputer.c +++ b/core/libdivecomputer.c @@ -38,6 +38,16 @@ static int stoptime, stopdepth, ndl, po2, cns; static bool in_deco, first_temp_is_air; static int current_gas_index; +/* logging bits from libdivecomputer */ +#ifndef __ANDROID__ +#define INFO(context, fmt, ...) fprintf(stderr, "INFO: " fmt "\n", ##__VA_ARGS__) +#define ERROR(context, fmt, ...) fprintf(stderr, "ERROR: " fmt "\n", ##__VA_ARGS__) +#else +#include <android/log.h> +#define INFO(context, fmt, ...) __android_log_print(ANDROID_LOG_DEBUG, __FILE__, "INFO: " fmt "\n", ##__VA_ARGS__) +#define ERROR(context, fmt, ...) __android_log_print(ANDROID_LOG_DEBUG, __FILE__, "ERROR: " fmt "\n", ##__VA_ARGS__) +#endif + /* * Directly taken from libdivecomputer's examples/common.c to improve * the error messages resulting from libdc's return codes @@ -1076,6 +1086,9 @@ const char *do_libdivecomputer_import(device_data_t *data) #ifdef SERIAL_FTDI } else if (!strcmp(data->devname, "ftdi")) { rc = dc_context_set_custom_serial(data->context, &serial_ftdi_ops); + INFO(0, "setting up ftdi ops"); +#else + INFO(0, "FTDI disabled"); #endif } @@ -1086,7 +1099,7 @@ const char *do_libdivecomputer_import(device_data_t *data) { #endif rc = dc_device_open(&data->device, data->context, data->descriptor, data->devname); - + INFO(0, "dc_deveice_open error value of %d", rc); if (rc != DC_STATUS_SUCCESS && subsurface_access(data->devname, R_OK | W_OK) != 0) err = translate("gettextFromC", "Insufficient privileges to open the device %s %s (%s)"); } diff --git a/core/serial_ftdi.c b/core/serial_ftdi.c index eafe4f1d7..9b26517ab 100644 --- a/core/serial_ftdi.c +++ b/core/serial_ftdi.c @@ -121,6 +121,7 @@ static dc_status_t serial_ftdi_sleep (ftdi_serial_t *device, unsigned long timeo // Used internally for opening ftdi devices static int serial_ftdi_open_device (struct ftdi_context *ftdi_ctx) { + INFO(0, "serial_ftdi_open_device called"); int accepted_pids[] = { 0x6001, 0x6010, 0x6011, // Suunto (Smart Interface), Heinrichs Weikamp 0xF460, // Oceanic 0xF680, // Suunto @@ -131,6 +132,7 @@ static int serial_ftdi_open_device (struct ftdi_context *ftdi_ctx) for (i = 0; i < num_accepted_pids; i++) { pid = accepted_pids[i]; ret = ftdi_usb_open (ftdi_ctx, VID, pid); + INFO(0, "FTDI tried VID %04x pid %04x ret %d\n", VID, pid, ret); if (ret == -3) // Device not found continue; else @@ -145,13 +147,14 @@ static int serial_ftdi_open_device (struct ftdi_context *ftdi_ctx) // Initialise ftdi_context and use it to open the device static dc_status_t serial_ftdi_open (void **userdata, const char* name) { + INFO(0, "serial_ftdi_open called"); // Allocate memory. ftdi_serial_t *device = (ftdi_serial_t *) malloc (sizeof (ftdi_serial_t)); if (device == NULL) { SYSERROR (context, errno); return DC_STATUS_NOMEMORY; } - + INFO(0, "setting up ftdi_ctx"); struct ftdi_context *ftdi_ctx = ftdi_new(); if (ftdi_ctx == NULL) { free(device); @@ -171,6 +174,7 @@ static dc_status_t serial_ftdi_open (void **userdata, const char* name) device->nbits = 0; // Initialize device ftdi context + INFO(0, "initialize ftdi_ctx"); ftdi_init(ftdi_ctx); if (ftdi_set_interface(ftdi_ctx,INTERFACE_ANY)) { |