diff --git a/LogCore.cpp b/LogCore.cpp index 0532713..54b3fd1 100644 --- a/LogCore.cpp +++ b/LogCore.cpp @@ -17,16 +17,17 @@ //--------------------------------------------------------------------------- -void ShowOutput( const char * Name, const char * Buffer, const int Len, const long Duration ) +bool ShowOutput( const char * Heading, const short Show, const char * Buffer, int Len ) { - // Show Duration delay - if (Duration) { - printf( "Delay: %ld", Duration ); - } + // Validate values + if (!Buffer) + return false; + if (Len == -1) + Len = strlen( Buffer ); // Show Hex output - if (ShowOutBytes) { - printf( "%s in (hex): ", Name ); + if (Show & OUT_HEX) { + printf( "%s [%d]: ", Heading, Len ); for (int i=0; i 126)) { + if ((Show & OUT_CRLF) && ((Buffer[i] == '\r') || (Buffer[i] == '\n'))) + printf( "%c", Buffer[i] ); + else + printf( "." ); + } + else { + printf( "%c", Buffer[i] ); + } + } + } + if (!(Show & (OUT_ASIS | OUT_CRLF)) || (Buffer[Len-1] != '\n')) { printf( "\n" ); } } + return true; } //--------------------------------------------------------------------------- diff --git a/LogCore.h b/LogCore.h index 75ff0a0..96fa25f 100644 --- a/LogCore.h +++ b/LogCore.h @@ -17,12 +17,15 @@ //--------------------------------------------------------------------------- // Debug options -bool ShowOutBytes = true; -bool ShowOutHex = true; +const short + OUT_NORMAL = 1, + OUT_HEX = 2, + OUT_CRLF = 4, + OUT_ASIS = 8; //--------------------------------------------------------------------------- -void ShowOutput( const char * Name, const char * Buffer, const int Len, const long Duration ); +bool ShowOutput( const char * Heading, const short Show, const char * Buffer, int Len = -1 ); //--------------------------------------------------------------------------- diff --git a/PortCore.cpp b/PortCore.cpp index f2892b8..d2a2b1c 100644 --- a/PortCore.cpp +++ b/PortCore.cpp @@ -8,6 +8,7 @@ // redA Libraries #include "PortCore.h" #include "TimingCore.h" +#include "LogCore.h" // Standard C/C++ Libraries #include @@ -276,7 +277,7 @@ bool CPortCore::Maintain( int SocketHandle ) { // Handle buffer as packet InBuffer[ InLen ] = 0; - //ShowOutput( "Port", InBuffer, PortInLen, Duration ); + ShowOutput( "Port In", OUT_NORMAL|OUT_HEX, InBuffer, InLen ); // Write output to Port BytesWritten = 0; diff --git a/SocketCore.cpp b/SocketCore.cpp index b561836..7f855ad 100644 --- a/SocketCore.cpp +++ b/SocketCore.cpp @@ -8,6 +8,7 @@ // redA Libraries #include "TimingCore.h" #include "SocketCore.h" +#include "LogCore.h" // Standard C/C++ Libraries #include @@ -354,7 +355,7 @@ bool MaintainSocket( int PortHandle ) { // Handle buffer as packet SockInBuffer[ SockInLen ] = 0; - //ShowOutput( "Sock", SockInBuffer, SockInLen, Duration ); + ShowOutput( "Sock In", OUT_NORMAL|OUT_HEX, SockInBuffer, SockInLen ); // Write output to Port BytesWritten = 0;