From dcebad21c86f99ae70dc5298a9a6d9bbbe24a764 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gu=C3=B0ni=20M=C3=A1r=20Gilbert?= Date: Sun, 24 Apr 2022 09:30:20 +0000 Subject: [PATCH] Add missing spaces to ErrorCode messages Such that: MMU2:E=32766ErrorTitleTextDescription Becomes: MMU2:E=32766 ErrorTitle TextDescription Also simplified the process of combining ErrorTitle and TextDescription into the msg buffer by using snprintf. This is saver since we only use dstSize in one place instead of two. --- Firmware/mmu2.cpp | 4 ++-- Firmware/mmu2_error_converter.cpp | 8 ++++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/Firmware/mmu2.cpp b/Firmware/mmu2.cpp index b4c81b8f9..4ffa88c99 100644 --- a/Firmware/mmu2.cpp +++ b/Firmware/mmu2.cpp @@ -608,13 +608,13 @@ void MMU2::ReportError(ErrorCode ec) { if( ec != lastErrorCode ){ // deduplicate: only report changes in error codes into the log lastErrorCode = ec; - // Log error format: MMU2:E=32766 TextDescription + // Log error format: MMU2:E=32766 ErrorTitle TextDescription // The longest error description in errors_list.h is 144 bytes. // and the longest error title is 20 bytes. msg buffer needs // to have enough space to fit both. char msg[192]; - int len = snprintf(msg, sizeof(msg), "MMU2:E=%hu", (uint16_t)ec); + int len = snprintf(msg, sizeof(msg), "MMU2:E=%hu ", (uint16_t)ec); // Append a human readable form of the error code(s) TranslateErr((uint16_t)ec, &msg[len], 192 - len); diff --git a/Firmware/mmu2_error_converter.cpp b/Firmware/mmu2_error_converter.cpp index cb3d21ec6..08b1853e8 100644 --- a/Firmware/mmu2_error_converter.cpp +++ b/Firmware/mmu2_error_converter.cpp @@ -2,6 +2,7 @@ #include "mmu2/error_codes.h" #include "mmu2/errors_list.h" #include "language.h" +#include namespace MMU2 { @@ -92,8 +93,11 @@ void TranslateErr(uint16_t ec, char *dst, size_t dstSize) { uint16_t ei = MMUErrorCodeIndex(ec); // just to prevent the compiler from stripping the data structures from the final binary for now *dst = errorButtons[ei]; - strncpy_P(dst + 1, static_cast(pgm_read_ptr(&errorTitles[ei])), dstSize); - strncat_P(dst, static_cast(pgm_read_ptr(&errorDescs[ei])), dstSize); + snprintf( + dst, dstSize, "%S %S", + static_cast(pgm_read_ptr(&errorTitles[ei])), + static_cast(pgm_read_ptr(&errorDescs[ei])) + ); } } // namespace MMU2