You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
46 lines
804 B
46 lines
804 B
/*
|
|
* debug.cc
|
|
*
|
|
* Created on: 15.12.2017
|
|
* Author: steffen
|
|
*/
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
|
|
#include "debug.h"
|
|
|
|
char *int2hex (int val, char *buf, int len) {
|
|
char tmp[] = "0123456789ABCDEF";
|
|
int i;
|
|
unsigned int v;
|
|
|
|
if (buf == NULL) return NULL;
|
|
|
|
memset (buf, '0', len-1);
|
|
buf[len-1] = 0;
|
|
for (v = val, i = 0; i < len-1; i++) {
|
|
buf[len-2-i] = tmp[v % 16];
|
|
v = v >> 4;
|
|
}
|
|
|
|
return buf;
|
|
}
|
|
|
|
void debug_mem (char *c, int len) {
|
|
int i;
|
|
int v;
|
|
char _hexpos[32];
|
|
char _hexval[32];
|
|
|
|
for (i = 0; i < len; i++) {
|
|
if (i > 0 && (i % 16) == 0) printf ("\n");
|
|
if ((i % 16) == 0)
|
|
printf (" 0x%s ", int2hex(i, _hexpos, 5));
|
|
if ((i % 8) == 0) printf (" ");
|
|
v = (unsigned char) c[i];
|
|
printf ("%s ", int2hex(v, _hexval, 3));
|
|
}
|
|
printf ("\n");
|
|
};
|