Minor Update:
- Complete LogCore functions - Implement ShowOutput() in Port and Socket functions
This commit is contained in:
38
LogCore.cpp
38
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<Len; i++) {
|
||||
printf( "%02X ", Buffer[i] );
|
||||
}
|
||||
@@ -34,12 +35,29 @@ void ShowOutput( const char * Name, const char * Buffer, const int Len, const lo
|
||||
}
|
||||
|
||||
// Show normal output
|
||||
if (ShowOutHex) {
|
||||
printf( "%s in [%d]: %s", Name, Len, Buffer );
|
||||
if (Buffer[Len-1] != '\n') {
|
||||
if (Show & OUT_NORMAL) {
|
||||
printf( "%s [%d]: ", Heading, Len );
|
||||
if (Show & OUT_ASIS) {
|
||||
printf( "%s", Buffer );
|
||||
}
|
||||
else {
|
||||
for (int i=0; i<Len; i++) {
|
||||
if ((Buffer[i] < 32) || (Buffer[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;
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
|
||||
@@ -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 );
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
// redA Libraries
|
||||
#include "PortCore.h"
|
||||
#include "TimingCore.h"
|
||||
#include "LogCore.h"
|
||||
|
||||
// Standard C/C++ Libraries
|
||||
#include <stdio.h>
|
||||
@@ -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;
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
// redA Libraries
|
||||
#include "TimingCore.h"
|
||||
#include "SocketCore.h"
|
||||
#include "LogCore.h"
|
||||
|
||||
// Standard C/C++ Libraries
|
||||
#include <stdio.h>
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user