From 4a82fdc7f539992287599f4bf0cd69046506dd4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20M=C3=BCller?= Date: Fri, 12 Apr 2024 03:21:41 +0200 Subject: [PATCH] Extract hexDump function --- src/util.h | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/util.h b/src/util.h index a563f9c..586d0ec 100644 --- a/src/util.h +++ b/src/util.h @@ -246,6 +246,19 @@ enum class ExtendedChar { GreekSmallLetterPhi = 0xed, }; +String hexDump(String in) { + String out; + for (size_t i = 0; i < in.length(); ++i) { + auto hexChar = String(in[i], HEX); + if (hexChar.length() == 1) { + out.concat('0'); + } + out.concat(hexChar); + out.concat(' '); + } + return out; +} + /* * Message syntax: * separator: ~ @@ -299,13 +312,5 @@ void sendTextToSign( Serial1.print(toSend); Serial.println("Text sent to device: " + toSend); - Serial.print("Hex dump: "); - for (size_t i = 0; i < toSend.length(); ++i) { - auto hexChar = String(toSend[i], HEX); - if (hexChar.length() == 1) { - hexChar = '0' + hexChar; - } - Serial.print(hexChar + ' '); - } - Serial.println(); + Serial.println("Hex dump: " + hexDump(toSend)); }