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:  -  -  -  -  -  -  -  -
```
This commit is contained in:
axxel
2024-09-28 12:13:19 +02:00
committed by Marcus Meissner
parent 5b70cdf6dc
commit 4952b37efb

View File

@@ -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 */