From 4952b37efb2bb0358469c6a7d91bf2af39ad9d2f Mon Sep 17 00:00:00 2001 From: axxel Date: Sat, 28 Sep 2024 12:13:19 +0200 Subject: [PATCH] ptp2: make ptp_debug_data output easier to parse at a glance * replace "00 " with " - " * don't repeat lines with all zeros e.g.: ``` event 146: EOS prop d212 value changed, size 408 ((null)) 0x000: 0a - - - 01 - - - - - - - - - - - 0x010: - - - - - - - - - - - - - - - - [...]: 0x190: - - - - - - - - ``` --- camlibs/ptp2/ptp.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/camlibs/ptp2/ptp.c b/camlibs/ptp2/ptp.c index b1a754f49..328a2eb85 100644 --- a/camlibs/ptp2/ptp.c +++ b/camlibs/ptp2/ptp.c @@ -184,7 +184,10 @@ ptp_bytes2str(const uint8_t *data, int data_size, const char *fmt) static char line[16 * 3 + 1]; int pos = 0; for (int i = 0; i < data_size && pos < (int)sizeof(line); ++i) { - pos += snprintf(line + pos, sizeof(line) - pos, fmt, data[i]); + if (data[i] || fmt) + pos += snprintf(line + pos, sizeof(line) - pos, fmt ? fmt : "%02x ", data[i]); + else + pos += snprintf(line + pos, sizeof(line) - pos, " - "); } return line; } @@ -192,8 +195,15 @@ ptp_bytes2str(const uint8_t *data, int data_size, const char *fmt) void ptp_debug_data(PTPParams *params, const uint8_t* data, int size) { - for (int k = 0; k < size; k += 16) - ptp_debug (params, " 0x%03x: %s", k, ptp_bytes2str(data + k, MIN(16, size - k), "%02x ")); + uint8_t zeros[16] = { 0 }; + int zero_lines = 0; + for (int k = 0; k < size; k += 16) { + zero_lines = (size - k > 16 && memcmp(data + k, zeros, 16) == 0) ? zero_lines + 1 : 0; + if (zero_lines < 2) + ptp_debug (params, " 0x%03x: %s", k, ptp_bytes2str(data + k, MIN(16, size - k), NULL)); + else if (zero_lines == 2) + ptp_debug (params, " [...]: %s", ""); //ptp_bytes2str(zeros, 16, "%02x ")); + } } /* Pack / unpack functions */