kopia lustrzana https://github.com/Hamlib/Hamlib
Correct dump_hex output
Changed dump_hex so that there is only one call to rig_debug() per line. Signed-off-by: Nate Bargmann <n0nb@n0nb.us>Hamlib-1.2.14
rodzic
72c52d6e9a
commit
b0f9f805bb
78
src/debug.c
78
src/debug.c
|
@ -34,11 +34,11 @@
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <stdio.h> /* Standard input/output definitions */
|
#include <stdio.h> /* Standard input/output definitions */
|
||||||
#include <string.h> /* String function definitions */
|
#include <string.h> /* String function definitions */
|
||||||
#include <unistd.h> /* UNIX standard function definitions */
|
#include <unistd.h> /* UNIX standard function definitions */
|
||||||
#include <fcntl.h> /* File control definitions */
|
#include <fcntl.h> /* File control definitions */
|
||||||
#include <errno.h> /* Error number definitions */
|
#include <errno.h> /* Error number definitions */
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
|
@ -60,42 +60,40 @@ static rig_ptr_t rig_vprintf_arg;
|
||||||
*/
|
*/
|
||||||
void dump_hex(const unsigned char ptr[], size_t size)
|
void dump_hex(const unsigned char ptr[], size_t size)
|
||||||
{
|
{
|
||||||
int i;
|
/* example
|
||||||
char buf[DUMP_HEX_WIDTH+1];
|
* 0000 4b 30 30 31 34 35 30 30 30 30 30 30 30 35 30 32 K001450000000502
|
||||||
|
* 0010 30 30 0d 0a 00..
|
||||||
|
*/
|
||||||
|
char line[4 + 4 + 3 * DUMP_HEX_WIDTH + 4 + DUMP_HEX_WIDTH + 1];
|
||||||
|
unsigned char c;
|
||||||
|
int i;
|
||||||
|
|
||||||
if (!rig_need_debug(RIG_DEBUG_TRACE))
|
if (!rig_need_debug(RIG_DEBUG_TRACE))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
/* ASCII column */
|
line[sizeof(line) - 1] = '\0';
|
||||||
buf[DUMP_HEX_WIDTH] = '\0';
|
|
||||||
|
|
||||||
for(i=0; i<size; i++) {
|
for (i = 0; i < size; ++i) {
|
||||||
if (i % DUMP_HEX_WIDTH == 0)
|
if (i % DUMP_HEX_WIDTH == 0) {
|
||||||
rig_debug(RIG_DEBUG_TRACE,"%.4x ",i);
|
/* new line */
|
||||||
|
sprintf(line + 0, "%04x", i);
|
||||||
|
memset(line + 4, ' ', sizeof(line) - 4 - 1);
|
||||||
|
}
|
||||||
|
|
||||||
rig_debug(RIG_DEBUG_TRACE," %.2x", ptr[i]);
|
c = ptr[i];
|
||||||
|
|
||||||
/* printable ASCII? */
|
/* hex print */
|
||||||
if (ptr[i] >= ' ' && ptr[i] < 0x7f)
|
sprintf(line + 8 + 3 * (i % DUMP_HEX_WIDTH), "%02x", c);
|
||||||
buf[i%DUMP_HEX_WIDTH] = ptr[i];
|
line[8 + 3 * (i % DUMP_HEX_WIDTH) + 2] = ' '; /* no \0 */
|
||||||
else
|
|
||||||
buf[i%DUMP_HEX_WIDTH] = '.';
|
|
||||||
|
|
||||||
if (i % DUMP_HEX_WIDTH == DUMP_HEX_WIDTH-1)
|
/* ascii print */
|
||||||
rig_debug(RIG_DEBUG_TRACE," %s\n",buf);
|
line[8 + 3 * DUMP_HEX_WIDTH + 4 + (i % DUMP_HEX_WIDTH)] = (c >= ' ' && c < 0x7f) ? c : '.';
|
||||||
}
|
|
||||||
|
|
||||||
if (i % DUMP_HEX_WIDTH != 0) {
|
/* actually print the line */
|
||||||
/* Add some spaces in order to align right ASCII dump column */
|
if (i + 1 == size || (i && i % DUMP_HEX_WIDTH == DUMP_HEX_WIDTH - 1))
|
||||||
int j;
|
rig_debug(RIG_DEBUG_TRACE, "%s\n", line);
|
||||||
for (j = i % DUMP_HEX_WIDTH; j < DUMP_HEX_WIDTH; j++)
|
}
|
||||||
rig_debug(RIG_DEBUG_TRACE," ");
|
}
|
||||||
|
|
||||||
buf[i % DUMP_HEX_WIDTH] = '\0';
|
|
||||||
rig_debug(RIG_DEBUG_TRACE," %s\n",buf);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -147,16 +145,16 @@ void HAMLIB_API rig_debug(enum rig_debug_level_e debug_level, const char *fmt, .
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief set callback to handle debug messages
|
* \brief set callback to handle debug messages
|
||||||
* \param cb The callback to install
|
* \param cb The callback to install
|
||||||
* \param arg A Pointer to some private data to pass later on to the callback
|
* \param arg A Pointer to some private data to pass later on to the callback
|
||||||
*
|
*
|
||||||
* Install a callback for \a rig_debug messages.
|
* Install a callback for \a rig_debug messages.
|
||||||
\code
|
\code
|
||||||
int
|
int
|
||||||
rig_message_cb (enum rig_debug_level_e debug_level,
|
rig_message_cb (enum rig_debug_level_e debug_level,
|
||||||
rig_ptr_t user_data,
|
rig_ptr_t user_data,
|
||||||
const char *fmt,
|
const char *fmt,
|
||||||
va_list ap)
|
va_list ap)
|
||||||
{
|
{
|
||||||
char buf[1024];
|
char buf[1024];
|
||||||
|
|
||||||
|
|
Ładowanie…
Reference in New Issue