void Hex_print(const char *buf, int len)
{
static const char hex_char[] = "0123456789ABCDEF";
const unsigned char *ptr = (const unsigned char*) buf;
int i, nbytes, j, nlines;
char msgbuf[512], *dst;
std::string strTxt = "Recv Data";
nlines = ((len + 0x0f) >> 4);
if(NULL == msgbuf)
{
return;
}
sprintf(msgbuf, "--> addr=%08lx %ld bytes/n", buf, len);
for (j = 0; j < nlines; j++)
{
nbytes = (len < 16 ? len : 16);
dst = msgbuf;
memset(dst, 0x20, 4);
dst += 4;
for (i = 0; i < nbytes; i++)
{
unsigned char ival = *ptr++;
*dst++ = hex_char[(ival>>4)&0x0F];
*dst++ = hex_char[ival&0x0F];
*dst++ = ' ';
}
memset(dst, 0x20, 3 * (17 - nbytes));
dst += 3 * (17 - nbytes);
ptr -= nbytes;
for (i = 0; i < nbytes; i++)
{
if (*ptr >= 0x20 && *ptr <= 0x7e && *ptr != '%')
*dst = *ptr;
else
*dst = '.';
ptr++;
dst++;
}
*dst++ = '/n';
*dst = 0;
strTxt += msgbuf;
len -= nbytes;
}
m_ptrLogger->WriteDebug(__FILE__, __LINE__, //写入log
"%s", strTxt.c_str());
}