From 0945682dd17d1356016d43c4cc99b5b2ff6463ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Fillod=2C=20F8CFE?= Date: Sat, 9 Apr 2005 09:49:13 +0000 Subject: [PATCH] moved debug primitives from misc.c to proprer debug.c git-svn-id: https://hamlib.svn.sourceforge.net/svnroot/hamlib/trunk@2000 7ae35d74-ebe9-4afe-98af-79ac388436b8 --- src/Makefile.am | 2 +- src/debug.c | 174 ++++++++++++++++++++++++++++++++++++++++++++++++ src/misc.c | 138 +------------------------------------- 3 files changed, 176 insertions(+), 138 deletions(-) create mode 100644 src/debug.c diff --git a/src/Makefile.am b/src/Makefile.am index 485085e9f..eee3cbd01 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,7 +1,7 @@ INCLUDES = @INCLUDES@ @INCLTDL@ RIGSRC = rig.c serial.c misc.c register.c event.c cal.c conf.c tones.c \ rotator.c locator.c rot_reg.c rot_conf.c iofunc.c ext.c \ - mem.c settings.c parallel.c + mem.c settings.c parallel.c debug.c lib_LTLIBRARIES = libhamlib.la libhamlib_la_SOURCES = $(RIGSRC) diff --git a/src/debug.c b/src/debug.c new file mode 100644 index 000000000..a7c5ffe40 --- /dev/null +++ b/src/debug.c @@ -0,0 +1,174 @@ +/* + * Hamlib Interface - debug + * Copyright (c) 2000-2005 by Stephane Fillod + * + * $Id: debug.c,v 1.1 2005-04-09 09:49:12 fillods Exp $ + * + * This library is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program 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 Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include +#include /* Standard input/output definitions */ +#include /* String function definitions */ +#include /* UNIX standard function definitions */ +#include /* File control definitions */ +#include /* Error number definitions */ +#include +#include + +#include + +#include "misc.h" + +static int rig_debug_level = RIG_DEBUG_TRACE; +static FILE *rig_debug_stream; +static vprintf_cb_t rig_vprintf_cb; +static rig_ptr_t rig_vprintf_arg; + +/* + * Do a hex dump of the unsigned char array. + */ + +#define DUMP_HEX_WIDTH 16 + +void dump_hex(const unsigned char ptr[], size_t size) +{ + int i; + char buf[DUMP_HEX_WIDTH+1]; + + if (!rig_need_debug(RIG_DEBUG_TRACE)) + return; + + buf[DUMP_HEX_WIDTH] = '\0'; + + for(i=0; i= ' ' && ptr[i] < 0x7f) + buf[i%DUMP_HEX_WIDTH] = ptr[i]; + else + buf[i%DUMP_HEX_WIDTH] = '.'; + + if (i % DUMP_HEX_WIDTH == DUMP_HEX_WIDTH-1) + rig_debug(RIG_DEBUG_TRACE,"\t%s\n",buf); + } + + /* Add some spaces in order to align right ASCII dump column */ + if ((i / DUMP_HEX_WIDTH) > 0) { + int j; + for (j = i % DUMP_HEX_WIDTH; j < DUMP_HEX_WIDTH; j++) + rig_debug(RIG_DEBUG_TRACE," "); + } + + if (i % DUMP_HEX_WIDTH != DUMP_HEX_WIDTH-1) { + buf[i % DUMP_HEX_WIDTH] = '\0'; + rig_debug(RIG_DEBUG_TRACE,"\t%s\n",buf); + } + +} + + +/* + * rig_set_debug + * Change the current debug level + */ +void HAMLIB_API rig_set_debug(enum rig_debug_level_e debug_level) +{ + rig_debug_level = debug_level; +} + +/* + * rig_need_debug + * Usefull for dump_hex, etc. + */ +int HAMLIB_API rig_need_debug(enum rig_debug_level_e debug_level) +{ + return (debug_level <= rig_debug_level); +} + +/* + * rig_debug + * Default is debugging messages are done through stderr + */ +void HAMLIB_API rig_debug(enum rig_debug_level_e debug_level, const char *fmt, ...) +{ + va_list ap; + + if (!rig_need_debug(debug_level)) + return; + + + va_start(ap, fmt); + + if (rig_vprintf_cb) { + + rig_vprintf_cb(debug_level, rig_vprintf_arg, fmt, ap); + + } else { + if (!rig_debug_stream) + rig_debug_stream = stderr; + + vfprintf (rig_debug_stream, fmt, ap); + } + + va_end(ap); +} + +/** + * \brief set callback to handle debug messages + * \param cb The callback to install + * \param arg A Pointer to some private data to pass later on to the callback + * + * Install a callback for \a rig_debug messages. + * + * \return RIG_OK if the operation has been sucessful, otherwise + * a negative value if an error occured (in which case, cause + * is set appropriately). + * + * \sa rig_debug() + */ +//typedef int (*vprintf_cb_t) (enum rig_debug_level_e debug_level, rig_ptr_t, const char *, va_list); +vprintf_cb_t rig_set_debug_callback(vprintf_cb_t cb, rig_ptr_t arg) +{ + vprintf_cb_t prev_cb = rig_vprintf_cb; + + rig_vprintf_cb = cb; + rig_vprintf_arg = arg; + + return prev_cb; +} + +/** + * \brief change stderr to some different output + * \param stream The stream to set output to + */ +FILE *rig_set_debug_file(FILE *stream) +{ + FILE *prev_stream = rig_debug_stream; + + rig_debug_stream = stream; + + return prev_stream; +} + diff --git a/src/misc.c b/src/misc.c index cc4c98c5d..83e0e5ef5 100644 --- a/src/misc.c +++ b/src/misc.c @@ -2,7 +2,7 @@ * Hamlib Interface - toolbox * Copyright (c) 2000-2005 by Stephane Fillod * - * $Id: misc.c,v 1.37 2005-04-06 21:27:28 fillods Exp $ + * $Id: misc.c,v 1.38 2005-04-09 09:49:12 fillods Exp $ * * This library is free software; you can redistribute it and/or modify * it under the terms of the GNU Library General Public License as @@ -39,58 +39,6 @@ #include "misc.h" - -static int rig_debug_level = RIG_DEBUG_TRACE; -static FILE *rig_debug_stream; -static vprintf_cb_t rig_vprintf_cb; -static rig_ptr_t rig_vprintf_arg; - -/* - * Do a hex dump of the unsigned char array. - */ - -#define DUMP_HEX_WIDTH 16 - -void dump_hex(const unsigned char ptr[], size_t size) -{ - int i; - char buf[DUMP_HEX_WIDTH+1]; - - if (!rig_need_debug(RIG_DEBUG_TRACE)) - return; - - buf[DUMP_HEX_WIDTH] = '\0'; - - for(i=0; i= ' ' && ptr[i] < 0x7f) - buf[i%DUMP_HEX_WIDTH] = ptr[i]; - else - buf[i%DUMP_HEX_WIDTH] = '.'; - - if (i % DUMP_HEX_WIDTH == DUMP_HEX_WIDTH-1) - rig_debug(RIG_DEBUG_TRACE,"\t%s\n",buf); - } - - /* Add some spaces in order to align right ASCII dump column */ - if ((i / DUMP_HEX_WIDTH) > 0) { - int j; - for (j = i % DUMP_HEX_WIDTH; j < DUMP_HEX_WIDTH; j++) - rig_debug(RIG_DEBUG_TRACE," "); - } - - if (i % DUMP_HEX_WIDTH != DUMP_HEX_WIDTH-1) { - buf[i % DUMP_HEX_WIDTH] = '\0'; - rig_debug(RIG_DEBUG_TRACE,"\t%s\n",buf); - } - -} - - /* * Convert a long long (eg. frequency in Hz) to 4-bit BCD digits, * packed two digits per octet, in little-endian order. @@ -197,90 +145,6 @@ unsigned long long HAMLIB_API from_bcd_be(const unsigned char bcd_data[], unsign return f; } -/* - * rig_set_debug - * Change the current debug level - */ -void HAMLIB_API rig_set_debug(enum rig_debug_level_e debug_level) -{ - rig_debug_level = debug_level; -} - -/* - * rig_need_debug - * Usefull for dump_hex, etc. - */ -int HAMLIB_API rig_need_debug(enum rig_debug_level_e debug_level) -{ - return (debug_level <= rig_debug_level); -} - -/* - * rig_debug - * Default is debugging messages are done through stderr - */ -void HAMLIB_API rig_debug(enum rig_debug_level_e debug_level, const char *fmt, ...) -{ - va_list ap; - - if (!rig_need_debug(debug_level)) - return; - - - va_start(ap, fmt); - - if (rig_vprintf_cb) { - - rig_vprintf_cb(debug_level, rig_vprintf_arg, fmt, ap); - - } else { - if (!rig_debug_stream) - rig_debug_stream = stderr; - - vfprintf (rig_debug_stream, fmt, ap); - } - - va_end(ap); -} - -/** - * \brief set callback to handle debug messages - * \param cb The callback to install - * \param arg A Pointer to some private data to pass later on to the callback - * - * Install a callback for \a rig_debug messages. - * - * \return RIG_OK if the operation has been sucessful, otherwise - * a negative value if an error occured (in which case, cause - * is set appropriately). - * - * \sa rig_debug() - */ -//typedef int (*vprintf_cb_t) (enum rig_debug_level_e debug_level, rig_ptr_t, const char *, va_list); -vprintf_cb_t rig_set_debug_callback(vprintf_cb_t cb, rig_ptr_t arg) -{ - vprintf_cb_t prev_cb = rig_vprintf_cb; - - rig_vprintf_cb = cb; - rig_vprintf_arg = arg; - - return prev_cb; -} - -/** - * \brief change stderr to some different output - * \param stream The stream to set output to - */ -FILE *rig_set_debug_file(FILE *stream) -{ - FILE *prev_stream = rig_debug_stream; - - rig_debug_stream = stream; - - return prev_stream; -} - - #ifndef llabs #define llabs(a) ((a)<0?-(a):(a))