This commit is contained in:
2026-06-26 00:30:13 +02:00
commit b27cd76ca8
122 changed files with 37290 additions and 0 deletions
+39
View File
@@ -0,0 +1,39 @@
#include "stdio.h"
#include <ctype.h>
#include "hexdump.h"
void hexdump (const char *label, const uint8_t *data, size_t len) {
if (label)
iprintf ("%s (len=%u):\n", label, len);
for (size_t i = 0; i < len; i += 16) {
iprintf ("%04u ", i); // offset
for (size_t j = 0; j < 16; j++) {
if (i + j < len)
iprintf ("%02X ", data[i + j]);
else
iprintf (" "); // pad spacing
}
iprintf (" ");
for (size_t j = 0; j < 16 && i + j < len; j++) {
uint8_t c = data[i + j];
iprintf ("%c", isprint (c) ? c : '.');
}
iprintf ("\n");
}
}
void hexdump_compact(const uint8_t* data, size_t len, char* out, size_t out_size) {
size_t pos = 0;
for (size_t i = 0; i < len; i++) {
if (pos + 2 >= out_size) break; // make sure we don¡¯t overflow
snprintf(out + pos, 3, "%02x", data[i]); // 2 chars + null terminator
pos += 2;
}
if (pos < out_size)
out[pos] = '\0';
else
out[out_size - 1] = '\0'; // ensure null termination
}
+11
View File
@@ -0,0 +1,11 @@
#ifndef HEXDUMP_HEADER
#define HEXDUMP_HEADER
#include "stddef.h"
#include "stdint.h"
void hexdump (const char *label, const uint8_t *data, size_t len);
void hexdump_compact(const uint8_t* data, size_t len, char* out, size_t out_size);
#endif
+33
View File
@@ -0,0 +1,33 @@
#ifndef LOGGER_HEADER
#define LOGGER_HEADER
#include <stdio.h>
// Log levels as integers for easy comparison
#define LOG_LEVEL_ERROR 0
#define LOG_LEVEL_WARN 1
#define LOG_LEVEL_INFO 2
#define LOG_LEVEL_DEBUG 3
#define LOG_LEVEL_VERBOSE 4
// Current log level (change at runtime or compile-time)
#ifndef CURRENT_LOG_LEVEL
#define CURRENT_LOG_LEVEL LOG_LEVEL_DEBUG
#endif
// Internal macro to check log level
#define LOG_PRINT_IF(level, levelStr, tag, fmt, ...) \
do { \
if ((level) <= CURRENT_LOG_LEVEL) { \
printf("[%s] %s: " fmt "\r\n", levelStr, tag, ##__VA_ARGS__); \
} \
} while(0)
// ESP-like shortcuts
#define MESH_LOGE(tag, fmt, ...) LOG_PRINT_IF(LOG_LEVEL_ERROR, "E", tag, fmt, ##__VA_ARGS__)
#define MESH_LOGW(tag, fmt, ...) LOG_PRINT_IF(LOG_LEVEL_WARN, "W", tag, fmt, ##__VA_ARGS__)
#define MESH_LOGI(tag, fmt, ...) LOG_PRINT_IF(LOG_LEVEL_INFO, "I", tag, fmt, ##__VA_ARGS__)
#define MESH_LOGD(tag, fmt, ...) LOG_PRINT_IF(LOG_LEVEL_DEBUG, "D", tag, fmt, ##__VA_ARGS__)
#define MESH_LOGV(tag, fmt, ...) LOG_PRINT_IF(LOG_LEVEL_VERBOSE, "V", tag, fmt, ##__VA_ARGS__)
#endif