Skip to content

Commit

Permalink
chore: enhanced debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex4386 committed Jun 16, 2024
1 parent e8e0ea0 commit 20bfacf
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions src/scenes/mtp/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,33 @@ const char hex[] = "0123456789ABCDEF";

void print_bytes(char* tag, uint8_t* bytes, size_t len) {
FURI_LOG_I("MTP", "Dumping bytes - TAG: %s", tag);
int lines = len / 16;
int lines = len > 0 ? (len / 16) + 1 : 0;
size_t last_line_len = len % 16;
char* line = (char*)malloc(16 * 3 + 1);
char* line = (char*)malloc(16 * 3 + 3 + 16 + 1);
for(int i = 0; i < lines; i++) {
int line_len = i == lines - 1 ? last_line_len : 16;
for(int j = 0; j < line_len; j++) {
for(int j = 0; j < 16; j++) {
if(j >= line_len) {
line[j * 3] = ' ';
line[j * 3 + 1] = ' ';
line[j * 3 + 2] = ' ';
continue;
}

// write hex without sprintf
line[j * 3] = hex[bytes[i * 16 + j] >> 4];
line[j * 3 + 1] = hex[bytes[i * 16 + j] & 0x0F];
line[j * 3 + 2] = ' ';
}
line[16 * 3] = '\0';
line[16 * 3] = ' ';
line[16 * 3 + 1] = '|';
line[16 * 3 + 2] = ' ';
for(int j = 0; j < line_len; j++) {
// write ascii without sprintf
line[16 * 3 + 3 + j] =
bytes[i * 16 + j] >= 32 && bytes[i * 16 + j] <= 126 ? bytes[i * 16 + j] : '.';
}
line[16 * 3 + 3 + line_len] = '\0';
FURI_LOG_I("MTP", line);
}
free(line);
Expand Down

0 comments on commit 20bfacf

Please sign in to comment.