Important Update:

- Implemented new Util library:
  - Convert Bytes to Hex/Bin/Safe string
  - Convert HexString to Bytes
  - Search String for substring function
- Use Util library in LogCore for String conversions
This commit is contained in:
Charl Wentzel
2019-04-15 17:26:52 +02:00
parent 889df6c7de
commit 0046edc251
4 changed files with 224 additions and 21 deletions

View File

@@ -12,6 +12,7 @@
// redA Libraries
#include "LogCore.h"
#include "DateTimeCore.h"
#include "UtilCore.h"
//---------------------------------------------------------------------------
@@ -176,18 +177,9 @@ bool CLogCore::Output( EDebugLevel DebugLevel, EDebugLevel MsgLevel, const short
}
else if (OutFormat == loNormal)
{
// Ignore \r\n
for (int i=0; i<Len; i++) {
if ((Buffer[i] < 32) || (Buffer[i] > 126)) {
if (((Buffer[i] == '\r') || (Buffer[i] == '\n')) && !NoCrLf)
fprintf( OutputFile, "%c", Buffer[i] );
else
fprintf( OutputFile, "." );
}
else {
fprintf( OutputFile, "%c", Buffer[i] );
}
}
// Remove special char
fprintf( OutputFile, "%s", BytesToSafeStr(Buffer, Len, NoCrLf, '.') );
// Add EOL if not present or ignored
if (NoCrLf || (Buffer[Len-1] != '\n')) {
fprintf( OutputFile, "\n" );
@@ -196,19 +188,13 @@ bool CLogCore::Output( EDebugLevel DebugLevel, EDebugLevel MsgLevel, const short
else if (OutFormat == loHex)
{
// Print Hex values of individual bytes
for (int i=0; i<Len; i++) {
fprintf( OutputFile, "%02X ", (unsigned char)Buffer[i] );
}
fprintf( OutputFile, "%s", BytesToHexStr(Buffer, Len, " ") );
fprintf( OutputFile, "\n" );
}
else if (OutFormat == loBin)
{
// Print each byte as 8-bit binary
for (int i=0; i<Len; i++) {
fprintf( OutputFile, "%c%c%c%c%c%c%c%c ",
(Buffer[i] & 0x80)?'1':'0', (Buffer[i] & 0x40)?'1':'0', (Buffer[i] & 0x20)?'1':'0', (Buffer[i] & 0x10)?'1':'0',
(Buffer[i] & 0x08)?'1':'0', (Buffer[i] & 0x04)?'1':'0', (Buffer[i] & 0x02)?'1':'0', (Buffer[i] & 0x01)?'1':'0' );
}
fprintf( OutputFile, "%s", BytesToBinStr(Buffer, Len, " ") );
fprintf( OutputFile, "\n" );
}
return true;