Important update:
- Bug fix: make DateTimeCore functions linkable by using it in CLogCore - CLogCore: - Rename FileOutput -> OutputFile - Add DateTimeStr to Output if FileNo > 3
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* DateTimeCore.cpp
|
* DateTimeCore.cpp
|
||||||
*
|
*
|
||||||
* Created on: 3 Mar 2017
|
* Created on: 3 March 2017
|
||||||
* Author: wentzelc
|
* Author: wentzelc
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -13,14 +13,12 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <time.h>
|
||||||
//#include <stdlib.h>
|
|
||||||
//#include <unistd.h>
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
// Variable used to temp values with
|
// Variable used to temp values with
|
||||||
char ReturnStr[20];
|
static char ReturnStr[20];
|
||||||
|
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
/* none */
|
/* none */
|
||||||
|
|
||||||
// Standard C/C++ Libraries
|
// Standard C/C++ Libraries
|
||||||
#include <time.h>
|
#include <cstdlib>
|
||||||
|
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|||||||
49
LogCore.cpp
49
LogCore.cpp
@@ -7,6 +7,7 @@
|
|||||||
|
|
||||||
// redA Libraries
|
// redA Libraries
|
||||||
#include "LogCore.h"
|
#include "LogCore.h"
|
||||||
|
#include "DateTimeCore.h"
|
||||||
|
|
||||||
// Standard C/C++ Libraries
|
// Standard C/C++ Libraries
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
@@ -22,9 +23,9 @@ char LogStr[1000]; // Temporary var to create log messages,
|
|||||||
|
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
CLogCore::CLogCore( FILE * pFileOutput )
|
CLogCore::CLogCore( FILE * pOutputFile )
|
||||||
{
|
{
|
||||||
FileOutput = pFileOutput;
|
OutputFile = pOutputFile;
|
||||||
}
|
}
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
@@ -37,14 +38,19 @@ bool CLogCore::Message( EDebugLevel DebugLevel, EDebugLevel MsgLevel, const char
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Check debug level
|
// Check debug level
|
||||||
if (!FileOutput || (MsgLevel > DebugLevel)) {
|
if (!OutputFile || (MsgLevel > DebugLevel)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Show normal output
|
// Show Date & Time
|
||||||
|
if (OutputFile->_fileno > 3) {
|
||||||
|
fprintf( OutputFile, "%s", GetDateTimeStr( "/", ":" ));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Print formated message
|
||||||
va_start( ArgPtr, Format );
|
va_start( ArgPtr, Format );
|
||||||
vfprintf( FileOutput, Format, ArgPtr );
|
vfprintf( OutputFile, Format, ArgPtr );
|
||||||
fprintf( FileOutput, "\r\n" );
|
fprintf( OutputFile, "\r\n" );
|
||||||
va_end( ArgPtr );
|
va_end( ArgPtr );
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -59,7 +65,7 @@ bool CLogCore::Output( EDebugLevel DebugLevel, EDebugLevel MsgLevel, const short
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Check debug level
|
// Check debug level
|
||||||
if (!FileOutput || (MsgLevel > DebugLevel)) {
|
if (!OutputFile || (MsgLevel > DebugLevel)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -67,10 +73,15 @@ bool CLogCore::Output( EDebugLevel DebugLevel, EDebugLevel MsgLevel, const short
|
|||||||
if (Len == -1)
|
if (Len == -1)
|
||||||
Len = strlen( Buffer );
|
Len = strlen( Buffer );
|
||||||
|
|
||||||
|
// Show date & time
|
||||||
|
if (OutputFile->_fileno > 3) {
|
||||||
|
fprintf( OutputFile, "%s", GetDateTimeStr( "/", ":" ));
|
||||||
|
}
|
||||||
|
|
||||||
// Show Lead
|
// Show Lead
|
||||||
if (Format && *Format) {
|
if (Format && *Format) {
|
||||||
va_start( ArgPtr, Format );
|
va_start( ArgPtr, Format );
|
||||||
vfprintf( FileOutput, Format, ArgPtr );
|
vfprintf( OutputFile, Format, ArgPtr );
|
||||||
va_end( ArgPtr );
|
va_end( ArgPtr );
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -78,11 +89,11 @@ bool CLogCore::Output( EDebugLevel DebugLevel, EDebugLevel MsgLevel, const short
|
|||||||
if (Show & OUT_COUNT)
|
if (Show & OUT_COUNT)
|
||||||
{
|
{
|
||||||
// Print byte count
|
// Print byte count
|
||||||
fprintf( FileOutput, " [%d] ", Len );
|
fprintf( OutputFile, " [%d] ", Len );
|
||||||
|
|
||||||
// EOL if only count wanted
|
// EOL if only count wanted
|
||||||
if (Show & OUT_COUNT) {
|
if (Show & OUT_COUNT) {
|
||||||
fprintf( FileOutput, "\n" );
|
fprintf( OutputFile, "\n" );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -91,25 +102,25 @@ bool CLogCore::Output( EDebugLevel DebugLevel, EDebugLevel MsgLevel, const short
|
|||||||
{
|
{
|
||||||
if (Show & OUT_ASIS) {
|
if (Show & OUT_ASIS) {
|
||||||
// Print entire buffer as is (line feeds included)
|
// Print entire buffer as is (line feeds included)
|
||||||
fprintf( FileOutput, "%s", Buffer );
|
fprintf( OutputFile, "%s", Buffer );
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// Ignore \r\n
|
// Ignore \r\n
|
||||||
for (int i=0; i<Len; i++) {
|
for (int i=0; i<Len; i++) {
|
||||||
if ((Buffer[i] < 32) || (Buffer[i] > 126)) {
|
if ((Buffer[i] < 32) || (Buffer[i] > 126)) {
|
||||||
if ((Show & OUT_CRLF) && ((Buffer[i] == '\r') || (Buffer[i] == '\n')))
|
if ((Show & OUT_CRLF) && ((Buffer[i] == '\r') || (Buffer[i] == '\n')))
|
||||||
fprintf( FileOutput, "%c", Buffer[i] );
|
fprintf( OutputFile, "%c", Buffer[i] );
|
||||||
else
|
else
|
||||||
fprintf( FileOutput, "." );
|
fprintf( OutputFile, "." );
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
fprintf( FileOutput, "%c", Buffer[i] );
|
fprintf( OutputFile, "%c", Buffer[i] );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Add EOL if not present or ignored
|
// Add EOL if not present or ignored
|
||||||
if (!(Show & (OUT_ASIS | OUT_CRLF)) || (Buffer[Len-1] != '\n')) {
|
if (!(Show & (OUT_ASIS | OUT_CRLF)) || (Buffer[Len-1] != '\n')) {
|
||||||
fprintf( FileOutput, "\n" );
|
fprintf( OutputFile, "\n" );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -118,9 +129,9 @@ bool CLogCore::Output( EDebugLevel DebugLevel, EDebugLevel MsgLevel, const short
|
|||||||
{
|
{
|
||||||
// Print Hex values of individual bytes
|
// Print Hex values of individual bytes
|
||||||
for (int i=0; i<Len; i++) {
|
for (int i=0; i<Len; i++) {
|
||||||
fprintf( FileOutput, "%02X ", (unsigned char)Buffer[i] );
|
fprintf( OutputFile, "%02X ", (unsigned char)Buffer[i] );
|
||||||
}
|
}
|
||||||
fprintf( FileOutput, "\n" );
|
fprintf( OutputFile, "\n" );
|
||||||
}
|
}
|
||||||
|
|
||||||
// Show Binary output
|
// Show Binary output
|
||||||
@@ -128,10 +139,10 @@ bool CLogCore::Output( EDebugLevel DebugLevel, EDebugLevel MsgLevel, const short
|
|||||||
// Print each byte as 8-bit binary
|
// Print each byte as 8-bit binary
|
||||||
for (int i=0; i<Len; i++) {
|
for (int i=0; i<Len; i++) {
|
||||||
for (int j=0; j<8; j++) {
|
for (int j=0; j<8; j++) {
|
||||||
fprintf( FileOutput, "%d", (bool)((Buffer[i] << j) & 0x80) );
|
fprintf( OutputFile, "%d", (bool)((Buffer[i] << j) & 0x80) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fprintf( FileOutput, "\n" );
|
fprintf( OutputFile, "\n" );
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,10 +34,10 @@ typedef enum { dlNone = 0, dlLow = 1, dlMedium = 2, dlHigh = 3 } EDebugLevel;
|
|||||||
class CLogCore
|
class CLogCore
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
FILE * FileOutput;
|
FILE * OutputFile;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CLogCore( FILE * pFileOutput );
|
CLogCore( FILE * pOutputFile );
|
||||||
|
|
||||||
bool Message( EDebugLevel DebugLevel, EDebugLevel MsgLevel, const char * Format, ... );
|
bool Message( EDebugLevel DebugLevel, EDebugLevel MsgLevel, const char * Format, ... );
|
||||||
bool Output( EDebugLevel DebugLevel, EDebugLevel MsgLevel, const short Show, const char * Buffer, int Len, const char * Format, ... );
|
bool Output( EDebugLevel DebugLevel, EDebugLevel MsgLevel, const short Show, const char * Buffer, int Len, const char * Format, ... );
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
* Author: wentzelc
|
* Author: wentzelc
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// redA Librarie
|
// redA Libraries
|
||||||
#include "TimingCore.h"
|
#include "TimingCore.h"
|
||||||
|
|
||||||
// Standard C/C++ Libraries
|
// Standard C/C++ Libraries
|
||||||
@@ -64,3 +64,4 @@ bool Timeout( timeval StartTime, long MilliSeconds )
|
|||||||
return ((TimePassed(StartTime) > MilliSeconds)? true : false);
|
return ((TimePassed(StartTime) > MilliSeconds)? true : false);
|
||||||
}
|
}
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user