Skip to content

Commit

Permalink
Cleanup: Remove 'context' Reference from Logging Defines.
Browse files Browse the repository at this point in the history
Remove the reference to `context` from the defines used for logging, as
this is not used.

Signed-off-by: Michael Keller <mikeller@042.ch>
  • Loading branch information
mikeller authored and bstoeger committed May 16, 2024
1 parent 888704e commit b579342
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 89 deletions.
10 changes: 5 additions & 5 deletions core/libdivecomputer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ static int stoptime, stopdepth, ndl, po2, cns, heartbeat, bearing;
static bool in_deco, first_temp_is_air;
static int current_gas_index;

#define INFO(context, fmt, ...) report_info("INFO: " fmt, ##__VA_ARGS__)
#define ERROR(context, fmt, ...) report_info("ERROR: " fmt, ##__VA_ARGS__)
#define INFO(fmt, ...) report_info("INFO: " fmt, ##__VA_ARGS__)
#define ERROR(fmt, ...) report_info("ERROR: " fmt, ##__VA_ARGS__)

/*
* Directly taken from libdivecomputer's examples/common.c to improve
Expand Down Expand Up @@ -497,7 +497,7 @@ static void dev_info(device_data_t *, const char *fmt, ...)
va_end(ap);
progress_bar_text = buffer;
if (verbose)
INFO(0, "dev_info: %s", buffer);
INFO("dev_info: %s", buffer);

if (progress_callback)
(*progress_callback)(buffer);
Expand Down Expand Up @@ -1291,7 +1291,7 @@ static dc_status_t usbhid_device_open(dc_iostream_t **iostream, dc_context_t *co
dc_iterator_free (iterator);

if (!device) {
ERROR(context, "didn't find HID device");
ERROR("didn't find HID device");
return DC_STATUS_NODEVICE;
}
dev_info(data, "Opening USB HID device for %04x:%04x",
Expand Down Expand Up @@ -1508,7 +1508,7 @@ const char *do_libdivecomputer_import(device_data_t *data)
dev_info(data, "Connecting ...");
rc = dc_device_open(&data->device, data->context, data->descriptor, data->iostream);
if (rc != DC_STATUS_SUCCESS) {
INFO(0, "dc_device_open error value of %d", rc);
INFO("dc_device_open error value of %d", rc);
if (subsurface_access(data->devname, R_OK | W_OK) != 0)
#if defined(SUBSURFACE_MOBILE)
err = translate("gettextFromC", "Error opening the device %s %s (%s).\nIn most cases, in order to debug this issue, it is useful to send the developers the log files. You can copy them to the clipboard in the About dialog.");
Expand Down
92 changes: 46 additions & 46 deletions core/serial_ftdi.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@
#endif

#include "errorhelper.h"
#define INFO(context, fmt, ...) report_info("INFO: " fmt, ##__VA_ARGS__)
#define ERROR(context, fmt, ...) report_info("ERROR: " fmt, ##__VA_ARGS__)
//#define SYSERROR(context, errcode) ERROR(__FILE__ ":" __LINE__ ": %s", strerror(errcode))
#define SYSERROR(context, errcode) ;
#define INFO(fmt, ...) report_info("INFO: " fmt, ##__VA_ARGS__)
#define ERROR(fmt, ...) report_info("ERROR: " fmt, ##__VA_ARGS__)
//#define SYSERROR(context, errcode) ERROR(__FILE__ ":" __LINE__ ": %s", strerror(errcode))
#define SYSERROR(errcode) (void)errcode

#include "libdivecomputer.h"
#include <libdivecomputer/context.h>
Expand Down Expand Up @@ -119,7 +119,7 @@ static dc_status_t serial_ftdi_sleep (void *io, unsigned int timeout)
if (device == NULL)
return DC_STATUS_INVALIDARGS;

INFO (device->context, "Sleep: value=%u", timeout);
INFO ("Sleep: value=%u", timeout);

#ifdef _WIN32
Sleep((DWORD)timeout);
Expand All @@ -130,7 +130,7 @@ static dc_status_t serial_ftdi_sleep (void *io, unsigned int timeout)

while (nanosleep (&ts, &ts) != 0) {
if (errno != EINTR ) {
SYSERROR (device->context, errno);
SYSERROR (errno);
return DC_STATUS_IO;
}
}
Expand All @@ -143,7 +143,7 @@ static dc_status_t serial_ftdi_sleep (void *io, unsigned int timeout)
// Used internally for opening ftdi devices
static int serial_ftdi_open_device (struct ftdi_context *ftdi_ctx)
{
INFO(0, "serial_ftdi_open_device called");
INFO("serial_ftdi_open_device called");
int accepted_pids[] = {
0x6001, 0x6010, 0x6011, // Suunto (Smart Interface), Heinrichs Weikamp
0x6015, // possibly Aqualung
Expand All @@ -156,7 +156,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", VID, pid, ret);
INFO("FTDI tried VID %04x pid %04x ret %d", VID, pid, ret);
if (ret == -3) // Device not found
continue;
else
Expand All @@ -171,20 +171,20 @@ 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 **io, dc_context_t *context)
{
INFO(0, "serial_ftdi_open called");
INFO("serial_ftdi_open called");
// Allocate memory.
ftdi_serial_t *device = (ftdi_serial_t *) malloc (sizeof (ftdi_serial_t));
if (device == NULL) {
INFO(0, "couldn't allocate memory");
SYSERROR (context, errno);
INFO("couldn't allocate memory");
SYSERROR (errno);
return DC_STATUS_NOMEMORY;
}
INFO(0, "setting up ftdi_ctx");
INFO("setting up ftdi_ctx");
struct ftdi_context *ftdi_ctx = ftdi_new();
if (ftdi_ctx == NULL) {
INFO(0, "failed ftdi_new()");
INFO("failed ftdi_new()");
free(device);
SYSERROR (context, errno);
SYSERROR (errno);
return DC_STATUS_NOMEMORY;
}

Expand All @@ -202,31 +202,31 @@ static dc_status_t serial_ftdi_open (void **io, dc_context_t *context)
device->parity = 0;

// Initialize device ftdi context
INFO(0, "initialize ftdi_ctx");
INFO("initialize ftdi_ctx");
ftdi_init(ftdi_ctx);

if (ftdi_set_interface(ftdi_ctx,INTERFACE_ANY)) {
free(device);
ERROR (context, "%s", ftdi_get_error_string(ftdi_ctx));
ERROR ("%s", ftdi_get_error_string(ftdi_ctx));
return DC_STATUS_IO;
}

INFO(0, "call serial_ftdi_open_device");
INFO("call serial_ftdi_open_device");
if (serial_ftdi_open_device(ftdi_ctx) < 0) {
free(device);
ERROR (context, "%s", ftdi_get_error_string(ftdi_ctx));
ERROR ("%s", ftdi_get_error_string(ftdi_ctx));
return DC_STATUS_IO;
}

if (ftdi_usb_reset(ftdi_ctx)) {
free(device);
ERROR (context, "%s", ftdi_get_error_string(ftdi_ctx));
ERROR ("%s", ftdi_get_error_string(ftdi_ctx));
return DC_STATUS_IO;
}

if (ftdi_usb_purge_buffers(ftdi_ctx)) {
free(device);
ERROR (context, "%s", ftdi_get_error_string(ftdi_ctx));
ERROR ("%s", ftdi_get_error_string(ftdi_ctx));
return DC_STATUS_IO;
}

Expand All @@ -252,7 +252,7 @@ static dc_status_t serial_ftdi_close (void *io)

int ret = ftdi_usb_close(device->ftdi_ctx);
if (ret < 0) {
ERROR (device->context, "Unable to close the ftdi device : %d (%s)",
ERROR ("Unable to close the ftdi device : %d (%s)",
ret, ftdi_get_error_string(device->ftdi_ctx));
return ret;
}
Expand All @@ -275,15 +275,15 @@ static dc_status_t serial_ftdi_configure (void *io, unsigned int baudrate, unsig
if (device == NULL)
return DC_STATUS_INVALIDARGS;

INFO (device->context, "Configure: baudrate=%i, databits=%i, parity=%i, stopbits=%i, flowcontrol=%i",
INFO ("Configure: baudrate=%i, databits=%i, parity=%i, stopbits=%i, flowcontrol=%i",
baudrate, databits, parity, stopbits, flowcontrol);

enum ftdi_bits_type ft_bits;
enum ftdi_stopbits_type ft_stopbits;
enum ftdi_parity_type ft_parity;

if (ftdi_set_baudrate(device->ftdi_ctx, baudrate) < 0) {
ERROR (device->context, "%s", ftdi_get_error_string(device->ftdi_ctx));
ERROR ("%s", ftdi_get_error_string(device->ftdi_ctx));
return DC_STATUS_IO;
}

Expand Down Expand Up @@ -331,27 +331,27 @@ static dc_status_t serial_ftdi_configure (void *io, unsigned int baudrate, unsig

// Set the attributes
if (ftdi_set_line_property(device->ftdi_ctx, ft_bits, ft_stopbits, ft_parity)) {
ERROR (device->context, "%s", ftdi_get_error_string(device->ftdi_ctx));
ERROR ("%s", ftdi_get_error_string(device->ftdi_ctx));
return DC_STATUS_IO;
}

// Set the flow control.
switch (flowcontrol) {
case DC_FLOWCONTROL_NONE: /**< No flow control */
if (ftdi_setflowctrl(device->ftdi_ctx, SIO_DISABLE_FLOW_CTRL) < 0) {
ERROR (device->context, "%s", ftdi_get_error_string(device->ftdi_ctx));
ERROR ("%s", ftdi_get_error_string(device->ftdi_ctx));
return DC_STATUS_IO;
}
break;
case DC_FLOWCONTROL_HARDWARE: /**< Hardware (RTS/CTS) flow control */
if (ftdi_setflowctrl(device->ftdi_ctx, SIO_RTS_CTS_HS) < 0) {
ERROR (device->context, "%s", ftdi_get_error_string(device->ftdi_ctx));
ERROR ("%s", ftdi_get_error_string(device->ftdi_ctx));
return DC_STATUS_IO;
}
break;
case DC_FLOWCONTROL_SOFTWARE: /**< Software (XON/XOFF) flow control */
if (ftdi_setflowctrl(device->ftdi_ctx, SIO_XON_XOFF_HS) < 0) {
ERROR (device->context, "%s", ftdi_get_error_string(device->ftdi_ctx));
ERROR ("%s", ftdi_get_error_string(device->ftdi_ctx));
return DC_STATUS_IO;
}
break;
Expand All @@ -378,7 +378,7 @@ static dc_status_t serial_ftdi_set_timeout (void *io, int timeout)
if (device == NULL)
return DC_STATUS_INVALIDARGS;

INFO (device->context, "Timeout: value=%i", timeout);
INFO ("Timeout: value=%i", timeout);

device->timeout = timeout;

Expand Down Expand Up @@ -406,11 +406,11 @@ static dc_status_t serial_ftdi_read (void *io, void *data, size_t size, size_t *
if (n < 0) {
if (n == LIBUSB_ERROR_INTERRUPTED)
continue; //Retry.
ERROR (device->context, "%s", ftdi_get_error_string(device->ftdi_ctx));
ERROR ("%s", ftdi_get_error_string(device->ftdi_ctx));
return DC_STATUS_IO; //Error during read call.
} else if (n == 0) {
if (serial_ftdi_get_msec() - start_time > timeout) {
ERROR(device->context, "%s", "FTDI read timed out.");
ERROR("FTDI read timed out.");
return DC_STATUS_TIMEOUT;
}
serial_ftdi_sleep (device, 1);
Expand All @@ -419,7 +419,7 @@ static dc_status_t serial_ftdi_read (void *io, void *data, size_t size, size_t *
nbytes += n;
}

INFO (device->context, "Read %d bytes", nbytes);
INFO ("Read %d bytes", nbytes);

if (actual)
*actual = nbytes;
Expand All @@ -441,7 +441,7 @@ static dc_status_t serial_ftdi_write (void *io, const void *data, size_t size, s
if (n < 0) {
if (n == LIBUSB_ERROR_INTERRUPTED)
continue; // Retry.
ERROR (device->context, "%s", ftdi_get_error_string(device->ftdi_ctx));
ERROR ("%s", ftdi_get_error_string(device->ftdi_ctx));
return DC_STATUS_IO; // Error during write call.
} else if (n == 0) {
break; // EOF.
Expand All @@ -450,7 +450,7 @@ static dc_status_t serial_ftdi_write (void *io, const void *data, size_t size, s
nbytes += n;
}

INFO (device->context, "Wrote %d bytes", nbytes);
INFO ("Wrote %d bytes", nbytes);

if (actual)
*actual = nbytes;
Expand All @@ -467,26 +467,26 @@ static dc_status_t serial_ftdi_purge (void *io, dc_direction_t queue)

size_t input;
serial_ftdi_get_available (io, &input);
INFO (device->context, "Flush: queue=%u, input=%lu, output=%i", queue, (unsigned long)input,
INFO ("Flush: queue=%u, input=%lu, output=%i", queue, (unsigned long)input,
serial_ftdi_get_transmitted (device));

switch (queue) {
case DC_DIRECTION_INPUT: /**< Input direction */
if (ftdi_usb_purge_tx_buffer(device->ftdi_ctx)) {
ERROR (device->context, "%s", ftdi_get_error_string(device->ftdi_ctx));
ERROR ("%s", ftdi_get_error_string(device->ftdi_ctx));
return DC_STATUS_IO;
}
break;
case DC_DIRECTION_OUTPUT: /**< Output direction */
if (ftdi_usb_purge_rx_buffer(device->ftdi_ctx)) {
ERROR (device->context, "%s", ftdi_get_error_string(device->ftdi_ctx));
ERROR ("%s", ftdi_get_error_string(device->ftdi_ctx));
return DC_STATUS_IO;
}
break;
case DC_DIRECTION_ALL: /**< All directions */
default:
if (ftdi_usb_reset(device->ftdi_ctx)) {
ERROR (device->context, "%s", ftdi_get_error_string(device->ftdi_ctx));
ERROR ("%s", ftdi_get_error_string(device->ftdi_ctx));
return DC_STATUS_IO;
}
break;
Expand All @@ -502,10 +502,10 @@ static dc_status_t serial_ftdi_set_break (void *io, unsigned int level)
if (device == NULL)
return DC_STATUS_INVALIDARGS;

INFO (device->context, "Break: value=%i", level);
INFO ("Break: value=%i", level);

if (ftdi_set_line_property2(device->ftdi_ctx, device->databits, device->stopbits, device->parity, level)) {
ERROR (device->context, "%s", ftdi_get_error_string(device->ftdi_ctx));
ERROR ("%s", ftdi_get_error_string(device->ftdi_ctx));
return DC_STATUS_IO;
}

Expand All @@ -519,10 +519,10 @@ static dc_status_t serial_ftdi_set_dtr (void *io, unsigned int value)
if (device == NULL)
return DC_STATUS_INVALIDARGS;

INFO (device->context, "DTR: value=%u", value);
INFO ("DTR: value=%u", value);

if (ftdi_setdtr(device->ftdi_ctx, value)) {
ERROR (device->context, "%s", ftdi_get_error_string(device->ftdi_ctx));
ERROR ("%s", ftdi_get_error_string(device->ftdi_ctx));
return DC_STATUS_IO;
}

Expand All @@ -536,10 +536,10 @@ static dc_status_t serial_ftdi_set_rts (void *io, unsigned int level)
if (device == NULL)
return DC_STATUS_INVALIDARGS;

INFO (device->context, "RTS: value=%u", level);
INFO ("RTS: value=%u", level);

if (ftdi_setrts(device->ftdi_ctx, level)) {
ERROR (device->context, "%s", ftdi_get_error_string(device->ftdi_ctx));
ERROR ("%s", ftdi_get_error_string(device->ftdi_ctx));
return DC_STATUS_IO;
}

Expand All @@ -565,12 +565,12 @@ dc_status_t ftdi_open(dc_iostream_t **iostream, dc_context_t *context)
.close = serial_ftdi_close,
};

INFO(device->contxt, "%s", "in ftdi_open");
INFO("in ftdi_open");
rc = serial_ftdi_open(&io, context);
if (rc != DC_STATUS_SUCCESS) {
INFO(device->contxt, "%s", "serial_ftdi_open() failed");
INFO("serial_ftdi_open() failed");
return rc;
}
INFO(device->contxt, "%s", "calling dc_custom_open())");
INFO("calling dc_custom_open())");
return dc_custom_open(iostream, context, DC_TRANSPORT_SERIAL, &callbacks, io);
}

0 comments on commit b579342

Please sign in to comment.