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:
26
LogCore.cpp
26
LogCore.cpp
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user