mirror of
https://github.com/meshtastic/firmware.git
synced 2025-04-30 19:29:17 +00:00
Trim extra vprintf and filter for unprintable characters
This commit is contained in:
parent
ca969e26a5
commit
6f3d7ca4d2
@ -50,27 +50,6 @@ size_t RedirectablePrint::write(uint8_t c)
|
|||||||
// serial port said (which could be zero)
|
// serial port said (which could be zero)
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t RedirectablePrint::vprintf(const char *format, va_list arg)
|
|
||||||
{
|
|
||||||
va_list copy;
|
|
||||||
static char printBuf[160];
|
|
||||||
|
|
||||||
va_copy(copy, arg);
|
|
||||||
size_t len = vsnprintf(printBuf, sizeof(printBuf), format, copy);
|
|
||||||
va_end(copy);
|
|
||||||
|
|
||||||
// If the resulting string is longer than sizeof(printBuf)-1 characters, the remaining characters are still counted for the
|
|
||||||
// return value
|
|
||||||
|
|
||||||
if (len > sizeof(printBuf) - 1) {
|
|
||||||
len = sizeof(printBuf) - 1;
|
|
||||||
printBuf[sizeof(printBuf) - 2] = '\n';
|
|
||||||
}
|
|
||||||
|
|
||||||
len = Print::write(printBuf, len);
|
|
||||||
return len;
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t RedirectablePrint::vprintf(const char *logLevel, const char *format, va_list arg)
|
size_t RedirectablePrint::vprintf(const char *logLevel, const char *format, va_list arg)
|
||||||
{
|
{
|
||||||
va_list copy;
|
va_list copy;
|
||||||
@ -87,14 +66,20 @@ size_t RedirectablePrint::vprintf(const char *logLevel, const char *format, va_l
|
|||||||
len = sizeof(printBuf) - 1;
|
len = sizeof(printBuf) - 1;
|
||||||
printBuf[sizeof(printBuf) - 2] = '\n';
|
printBuf[sizeof(printBuf) - 2] = '\n';
|
||||||
}
|
}
|
||||||
if (strcmp(logLevel, MESHTASTIC_LOG_LEVEL_DEBUG) == 0)
|
for (size_t f = 0; f < len; f++) {
|
||||||
Print::write("\u001b[34m", 6);
|
if (!std::isprint(static_cast<unsigned char>(printBuf[f])) && printBuf[f] != '\n')
|
||||||
if (strcmp(logLevel, MESHTASTIC_LOG_LEVEL_INFO) == 0)
|
printBuf[f] = '#';
|
||||||
Print::write("\u001b[32m", 6);
|
}
|
||||||
if (strcmp(logLevel, MESHTASTIC_LOG_LEVEL_WARN) == 0)
|
if (logLevel != nullptr) {
|
||||||
Print::write("\u001b[33m", 6);
|
if (strcmp(logLevel, MESHTASTIC_LOG_LEVEL_DEBUG) == 0)
|
||||||
if (strcmp(logLevel, MESHTASTIC_LOG_LEVEL_ERROR) == 0)
|
Print::write("\u001b[34m", 6);
|
||||||
Print::write("\u001b[31m", 6);
|
if (strcmp(logLevel, MESHTASTIC_LOG_LEVEL_INFO) == 0)
|
||||||
|
Print::write("\u001b[32m", 6);
|
||||||
|
if (strcmp(logLevel, MESHTASTIC_LOG_LEVEL_WARN) == 0)
|
||||||
|
Print::write("\u001b[33m", 6);
|
||||||
|
if (strcmp(logLevel, MESHTASTIC_LOG_LEVEL_ERROR) == 0)
|
||||||
|
Print::write("\u001b[31m", 6);
|
||||||
|
}
|
||||||
len = Print::write(printBuf, len);
|
len = Print::write(printBuf, len);
|
||||||
Print::write("\u001b[0m", 5);
|
Print::write("\u001b[0m", 5);
|
||||||
return len;
|
return len;
|
||||||
|
@ -44,7 +44,6 @@ class RedirectablePrint : public Print
|
|||||||
void log(const char *logLevel, const char *format, ...) __attribute__((format(printf, 3, 4)));
|
void log(const char *logLevel, const char *format, ...) __attribute__((format(printf, 3, 4)));
|
||||||
|
|
||||||
/** like printf but va_list based */
|
/** like printf but va_list based */
|
||||||
size_t vprintf(const char *format, va_list arg);
|
|
||||||
size_t vprintf(const char *logLevel, const char *format, va_list arg);
|
size_t vprintf(const char *logLevel, const char *format, va_list arg);
|
||||||
|
|
||||||
void hexDump(const char *logLevel, unsigned char *buf, uint16_t len);
|
void hexDump(const char *logLevel, unsigned char *buf, uint16_t len);
|
||||||
|
@ -24,7 +24,7 @@ void consolePrintf(const char *format, ...)
|
|||||||
{
|
{
|
||||||
va_list arg;
|
va_list arg;
|
||||||
va_start(arg, format);
|
va_start(arg, format);
|
||||||
console->vprintf(format, arg);
|
console->vprintf(nullptr, format, arg);
|
||||||
va_end(arg);
|
va_end(arg);
|
||||||
console->flush();
|
console->flush();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user