kopia lustrzana https://github.com/Hamlib/Hamlib
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-79ac388436b8Hamlib-1.2.5
rodzic
8b28265a63
commit
0945682dd1
|
@ -1,7 +1,7 @@
|
||||||
INCLUDES = @INCLUDES@ @INCLTDL@
|
INCLUDES = @INCLUDES@ @INCLTDL@
|
||||||
RIGSRC = rig.c serial.c misc.c register.c event.c cal.c conf.c tones.c \
|
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 \
|
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
|
lib_LTLIBRARIES = libhamlib.la
|
||||||
libhamlib_la_SOURCES = $(RIGSRC)
|
libhamlib_la_SOURCES = $(RIGSRC)
|
||||||
|
|
|
@ -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 <stdlib.h>
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include <stdio.h> /* Standard input/output definitions */
|
||||||
|
#include <string.h> /* String function definitions */
|
||||||
|
#include <unistd.h> /* UNIX standard function definitions */
|
||||||
|
#include <fcntl.h> /* File control definitions */
|
||||||
|
#include <errno.h> /* Error number definitions */
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#include <hamlib/rig.h>
|
||||||
|
|
||||||
|
#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<size; i++) {
|
||||||
|
if (i % DUMP_HEX_WIDTH == 0)
|
||||||
|
rig_debug(RIG_DEBUG_TRACE,"%.4x\t",i);
|
||||||
|
|
||||||
|
rig_debug(RIG_DEBUG_TRACE," %.2x", ptr[i]);
|
||||||
|
|
||||||
|
if (ptr[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;
|
||||||
|
}
|
||||||
|
|
138
src/misc.c
138
src/misc.c
|
@ -2,7 +2,7 @@
|
||||||
* Hamlib Interface - toolbox
|
* Hamlib Interface - toolbox
|
||||||
* Copyright (c) 2000-2005 by Stephane Fillod
|
* 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
|
* This library is free software; you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU Library General Public License as
|
* it under the terms of the GNU Library General Public License as
|
||||||
|
@ -39,58 +39,6 @@
|
||||||
#include "misc.h"
|
#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<size; i++) {
|
|
||||||
if (i % DUMP_HEX_WIDTH == 0)
|
|
||||||
rig_debug(RIG_DEBUG_TRACE,"%.4x\t",i);
|
|
||||||
|
|
||||||
rig_debug(RIG_DEBUG_TRACE," %.2x", ptr[i]);
|
|
||||||
|
|
||||||
if (ptr[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,
|
* Convert a long long (eg. frequency in Hz) to 4-bit BCD digits,
|
||||||
* packed two digits per octet, in little-endian order.
|
* 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;
|
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
|
#ifndef llabs
|
||||||
#define llabs(a) ((a)<0?-(a):(a))
|
#define llabs(a) ((a)<0?-(a):(a))
|
||||||
|
|
Ładowanie…
Reference in New Issue