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
|
// Validate values
|
||||||
if (Duration) {
|
if (!Buffer)
|
||||||
printf( "Delay: %ld", Duration );
|
return false;
|
||||||
}
|
if (Len == -1)
|
||||||
|
Len = strlen( Buffer );
|
||||||
|
|
||||||
// Show Hex output
|
// Show Hex output
|
||||||
if (ShowOutBytes) {
|
if (Show & OUT_HEX) {
|
||||||
printf( "%s in (hex): ", Name );
|
printf( "%s [%d]: ", Heading, Len );
|
||||||
for (int i=0; i<Len; i++) {
|
for (int i=0; i<Len; i++) {
|
||||||
printf( "%02X ", Buffer[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
|
// Show normal output
|
||||||
if (ShowOutHex) {
|
if (Show & OUT_NORMAL) {
|
||||||
printf( "%s in [%d]: %s", Name, Len, Buffer );
|
printf( "%s [%d]: ", Heading, Len );
|
||||||
if (Buffer[Len-1] != '\n') {
|
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" );
|
printf( "\n" );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|||||||
@@ -17,12 +17,15 @@
|
|||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
// Debug options
|
// Debug options
|
||||||
bool ShowOutBytes = true;
|
const short
|
||||||
bool ShowOutHex = true;
|
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
|
// redA Libraries
|
||||||
#include "PortCore.h"
|
#include "PortCore.h"
|
||||||
#include "TimingCore.h"
|
#include "TimingCore.h"
|
||||||
|
#include "LogCore.h"
|
||||||
|
|
||||||
// Standard C/C++ Libraries
|
// Standard C/C++ Libraries
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
@@ -276,7 +277,7 @@ bool CPortCore::Maintain( int SocketHandle )
|
|||||||
{
|
{
|
||||||
// Handle buffer as packet
|
// Handle buffer as packet
|
||||||
InBuffer[ InLen ] = 0;
|
InBuffer[ InLen ] = 0;
|
||||||
//ShowOutput( "Port", InBuffer, PortInLen, Duration );
|
ShowOutput( "Port In", OUT_NORMAL|OUT_HEX, InBuffer, InLen );
|
||||||
|
|
||||||
// Write output to Port
|
// Write output to Port
|
||||||
BytesWritten = 0;
|
BytesWritten = 0;
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
// redA Libraries
|
// redA Libraries
|
||||||
#include "TimingCore.h"
|
#include "TimingCore.h"
|
||||||
#include "SocketCore.h"
|
#include "SocketCore.h"
|
||||||
|
#include "LogCore.h"
|
||||||
|
|
||||||
// Standard C/C++ Libraries
|
// Standard C/C++ Libraries
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
@@ -354,7 +355,7 @@ bool MaintainSocket( int PortHandle )
|
|||||||
{
|
{
|
||||||
// Handle buffer as packet
|
// Handle buffer as packet
|
||||||
SockInBuffer[ SockInLen ] = 0;
|
SockInBuffer[ SockInLen ] = 0;
|
||||||
//ShowOutput( "Sock", SockInBuffer, SockInLen, Duration );
|
ShowOutput( "Sock In", OUT_NORMAL|OUT_HEX, SockInBuffer, SockInLen );
|
||||||
|
|
||||||
// Write output to Port
|
// Write output to Port
|
||||||
BytesWritten = 0;
|
BytesWritten = 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user