Open liudr opened 2 years ago
Note: @PaulStoffregen has the final say on some of these api changes...
But I don't think you want to blindly make the hex debug code built in there dump all of the time without that define, unless we instead have the dump code maybe public an the current hex dump dump call, only call it when in that state, otherwise we will suddenly have a lot more debug printing when we are not configured for debug...
Just an FYI, there are lots of hex dump functions, out there, but I have one that I hacked up that I use for debugging. https://github.com/KurtE/MemoryHexDump
Nothing very special, but does have hacks in it that if it finds lots of rows would be duplicated, it can optionally remove those lines.
Example from sketch I am playing with now:
...
memset(buffer, 0, sizeof(buffer));
const InfoToParseDXLPacket_t* pinfo_parse = dxl.rxStatusPacket(buffer, sizeof(buffer), 250);
if (pinfo_parse) {
DEBUG_SERIAL.printf("FastSyncRead time %u\n", micros() - start_time);
DEBUG_SERIAL.printf("InfoToParse: id:%u prot:%u err:%u Packet len:%u param len:%u\n", pinfo_parse->id,
pinfo_parse->protocol_ver, pinfo_parse->err_idx, pinfo_parse->packet_len, pinfo_parse->recv_param_len);
MemoryHexDump(DEBUG_SERIAL, buffer, sizeof(buffer), true);
...
Output:
=======================================================
Try Fast SyncRead
FastSyncRead time 1909
InfoToParse: id:254 prot:2 err:0 Packet len:49 param len:45
20004DE0 - 13 03 08 00 00 97 B4 00 03 06 08 00 00 DD E9 00 : ........ ........
20004DF0 - 05 01 08 00 00 C9 E2 00 02 02 08 00 00 16 B1 00 : ........ ........
20004E00 - 04 FA 07 00 00 39 17 00 06 FC 07 00 00 00 00 00 : .....9.. ........
20004E10 - 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 : ........ ........
... 27 duplicate line(s) removed.
20004FD0 - 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 : ........ ........
https://github.com/PaulStoffregen/USBHost_t36/blob/d41ed877a481e10dd02e5846ffa38af376008d42/USBHost_t36.h#L317
Suggest redefining USBHost::print_hexbytes() as USBHost::prn_hex() and just #define print_hexbytes() either as prn_hex() or as nothing. This way we can use the static function USBHost::prn_hex() to do hex dump while all the debug print lines in the existing code are still controlled by USBHOST_PRINT_DEBUG.