#include "debug.h" #include //#include #define MAX_HEX_STR_SIZE 36 #define MAX_TXT_STR_SIZE 19 #define MAX_HEX_TXT_LINE_SIZE (MAX_HEX_STR_SIZE + MAX_TXT_STR_SIZE + 2) static const char *ascii = "0123456789ABCDEF"; void print_buf( const char *pMes, const void *pv, int sz) { const char *ps = (const char *)pv; int i; char buf[256]; int pos = -1; pr_info( "%s%i:\n", pMes, sz); for( i=0; i> 4) & 0xF)]; buf[ ++pos] = ascii[ (ps[i] & 0xF)]; if( pos + 5 >= (int )sizeof(buf) ) { buf[ ++pos] = '\0'; pr_info( "%s", buf); pos = 0; } } buf[ ++pos] = '\n'; buf[ ++pos] = '\0'; pr_info( "%s", buf); } void print_buf_ext( const char *pMes, const void *pv, int sz) { const char *ps = (const char *)pv; uint8_t chr; int i, j, k, beg, cnt; char buf[256]; int pos = -1; pr_info( "%s%i:\n", pMes, sz); for( i=beg=0; i= 0x20 && chr < 0x7F) ? ps[k] : '.'); } buf[ ++pos] = '\n'; beg += cnt; if( (pos + MAX_HEX_TXT_LINE_SIZE >= (int )sizeof(buf)) || (i >= sz)) { buf[ ++pos] = '\0'; pr_info( "%s", buf); pos = -1; if( i >= sz) return; } } else if((i%4)==0) buf[ ++pos] = ' '; } buf[ ++pos] = ascii[ ((ps[i] >> 4) & 0xF)]; buf[ ++pos] = ascii[ (ps[i] & 0xF)]; } if( i >= sz) { cnt = i - beg; goto l_print; } } void format_buf( char *ps, int sz, const char *pBuf, int szBuf, int space, int lf) { int i; int pos = -1; for( i=0; i= sz) break; if(i) { if( lf && (i%lf)==0) ps[ ++pos] = '\n'; else if( space && (i%space)==0) ps[ ++pos] = ' '; } ps[ ++pos] = ascii[ ((pBuf[i] >> 4) & 0xF)]; ps[ ++pos] = ascii[ (pBuf[i] & 0xF)]; } ps[ ++pos] = '\0'; }